Simplify configuration and use Gradio's native CORS handling
Browse files
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 |
-
#
|
66 |
if __name__ == "__main__":
|
67 |
-
|
68 |
-
demo.queue() # Enable queue with default settings
|
69 |
demo.launch(
|
70 |
server_name="0.0.0.0",
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
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 |
)
|