pdarleyjr commited on
Commit
9274f42
·
1 Parent(s): 75a2106

Simplify configuration and use Gradio's native CORS handling

Browse files
Files changed (1) hide show
  1. app.py +6 -23
app.py CHANGED
@@ -1,19 +1,5 @@
1
  import gradio as gr
2
  from transformers import T5Tokenizer, T5ForConditionalGeneration
3
- from fastapi import FastAPI
4
- from fastapi.middleware.cors import CORSMiddleware
5
-
6
- # Create FastAPI app
7
- app = FastAPI()
8
-
9
- # Add CORS middleware
10
- app.add_middleware(
11
- CORSMiddleware,
12
- allow_origins=["https://pdarleyjr.github.io"], # Allow GitHub Pages domain
13
- allow_credentials=True,
14
- allow_methods=["*"],
15
- allow_headers=["*"],
16
- )
17
 
18
  # Load the base T5 model and tokenizer
19
  model = T5ForConditionalGeneration.from_pretrained('t5-small')
@@ -62,16 +48,13 @@ demo = gr.Interface(
62
  allow_flagging="never"
63
  )
64
 
65
- # Mount the Gradio app and launch
66
  if __name__ == "__main__":
67
- app = gr.mount_gradio_app(app, demo, path="/")
68
- demo.queue() # Enable queue with default settings
69
  demo.launch(
70
  server_name="0.0.0.0",
71
- server_port=7860,
72
- show_api=True, # Enable API documentation
73
- share=False, # Not needed in Spaces
74
- debug=True,
75
- root_path="",
76
- max_threads=40 # Increase max threads for better performance
77
  )
 
1
  import gradio as gr
2
  from transformers import T5Tokenizer, T5ForConditionalGeneration
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  # Load the base T5 model and tokenizer
5
  model = T5ForConditionalGeneration.from_pretrained('t5-small')
 
48
  allow_flagging="never"
49
  )
50
 
51
+ # Launch the app
52
  if __name__ == "__main__":
53
+ demo.queue()
 
54
  demo.launch(
55
  server_name="0.0.0.0",
56
+ share=False,
57
+ show_error=True,
58
+ allowed_paths=[],
59
+ cors_allowed_origins=["https://pdarleyjr.github.io"]
 
 
60
  )