Skip to content
This repository was archived by the owner on May 2, 2025. It is now read-only.

Commit 66cbde0

Browse files
committed
Update gradio for reload mode
1 parent d476369 commit 66cbde0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

gradio/gradio_app.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import sys
33

44
if "APP_PATH" in os.environ:
5-
os.chdir(os.environ["APP_PATH"])
6-
# fix sys.path for import
7-
sys.path.append(os.getcwd())
5+
app_path = os.path.abspath(os.environ["APP_PATH"])
6+
if os.getcwd() != app_path:
7+
# fix sys.path for import
8+
os.chdir(app_path)
9+
if app_path not in sys.path:
10+
sys.path.append(app_path)
811

912
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" # For some reason, transformers decided to use .isin for a simple op, which is not supported on MPS
1013

@@ -136,9 +139,10 @@ def del_select_coordinates(img, evt: gr.SelectData):
136139

137140
return (img[0], sections)
138141

139-
140-
model = load_model_cached()
141-
processor = load_processor_cached()
142+
# Load models if not already loaded in reload mode
143+
if 'model' not in globals():
144+
model = load_model_cached()
145+
processor = load_processor_cached()
142146

143147
with gr.Blocks(title="Texify") as demo:
144148
gr.Markdown("""
@@ -215,4 +219,5 @@ def show_image(file, num=1):
215219
outputs=[markdown_result]
216220
)
217221

218-
demo.launch()
222+
if __name__ == "__main__":
223+
demo.launch()

0 commit comments

Comments
 (0)