pdarleyjr commited on
Commit
79a19e9
·
1 Parent(s): 1310cf1

Simplify Gradio configuration and fix CORS settings

Browse files
Files changed (1) hide show
  1. app.py +6 -21
app.py CHANGED
@@ -3,18 +3,7 @@ from transformers import T5Tokenizer, T5ForConditionalGeneration
3
  from fastapi import FastAPI
4
  from fastapi.middleware.cors import CORSMiddleware
5
 
6
- # Create FastAPI app with CORS configuration
7
- app = FastAPI()
8
-
9
- # Add CORS middleware with specific origin
10
- app.add_middleware(
11
- CORSMiddleware,
12
- allow_origins=["https://pdarleyjr.github.io"], # Specifically allow the 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')
20
  tokenizer = T5Tokenizer.from_pretrained('t5-small')
@@ -76,17 +65,13 @@ demo = gr.Interface(
76
  # Enable queue
77
  demo.queue()
78
 
79
- # Mount the Gradio app with queue support
80
- app = gr.mount_gradio_app(app, demo, path="/")
81
-
82
- # Launch the app with proper queue configuration
83
  if __name__ == "__main__":
84
  demo.launch(
85
- server_name="0.0.0.0",
86
- server_port=7860, # Default Gradio port
87
  share=True,
88
- max_threads=40,
 
 
89
  show_error=True,
90
- root_path="",
91
- enable_queue=True
92
  )
 
3
  from fastapi import FastAPI
4
  from fastapi.middleware.cors import CORSMiddleware
5
 
6
+ # Initialize Gradio interface directly without FastAPI
 
 
 
 
 
 
 
 
 
 
 
7
  # Load the base T5 model and tokenizer
8
  model = T5ForConditionalGeneration.from_pretrained('t5-small')
9
  tokenizer = T5Tokenizer.from_pretrained('t5-small')
 
65
  # Enable queue
66
  demo.queue()
67
 
68
+ # Launch the app
 
 
 
69
  if __name__ == "__main__":
70
  demo.launch(
 
 
71
  share=True,
72
+ server_name="0.0.0.0",
73
+ server_port=7860,
74
+ allowed_paths=[],
75
  show_error=True,
76
+ cors_allowed_origins=["https://pdarleyjr.github.io"]
 
77
  )