Skip to content

Commit

Permalink
Update gradio for reload mode
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyao9184 committed Dec 25, 2024
1 parent d476369 commit 66cbde0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions gradio/gradio_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import sys

if "APP_PATH" in os.environ:
os.chdir(os.environ["APP_PATH"])
# fix sys.path for import
sys.path.append(os.getcwd())
app_path = os.path.abspath(os.environ["APP_PATH"])
if os.getcwd() != app_path:
# fix sys.path for import
os.chdir(app_path)
if app_path not in sys.path:
sys.path.append(app_path)

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

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

return (img[0], sections)


model = load_model_cached()
processor = load_processor_cached()
# Load models if not already loaded in reload mode
if 'model' not in globals():
model = load_model_cached()
processor = load_processor_cached()

with gr.Blocks(title="Texify") as demo:
gr.Markdown("""
Expand Down Expand Up @@ -215,4 +219,5 @@ def show_image(file, num=1):
outputs=[markdown_result]
)

demo.launch()
if __name__ == "__main__":
demo.launch()

0 comments on commit 66cbde0

Please sign in to comment.