pdarleyjr commited on
Commit
e213acb
·
1 Parent(s): 52bab4e

Added CORS support and improved API handling

Browse files
Files changed (2) hide show
  1. app.py +20 -2
  2. requirements.txt +3 -0
app.py CHANGED
@@ -1,5 +1,19 @@
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')
@@ -55,9 +69,13 @@ demo = gr.Interface(
55
  css="""
56
  #input-box { background-color: #f6f6f6; }
57
  #output-box { background-color: #f0f7ff; }
58
- """
 
59
  )
60
 
 
 
 
61
  # Launch the app
62
  if __name__ == "__main__":
63
- demo.launch()
 
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=["*"],
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')
 
69
  css="""
70
  #input-box { background-color: #f6f6f6; }
71
  #output-box { background-color: #f0f7ff; }
72
+ """,
73
+ allow_flagging="never"
74
  )
75
 
76
+ # Mount the Gradio app
77
+ app = gr.mount_gradio_app(app, demo, path="/")
78
+
79
  # Launch the app
80
  if __name__ == "__main__":
81
+ demo.launch(server_name="0.0.0.0", share=True)
requirements.txt CHANGED
@@ -2,3 +2,6 @@ transformers==4.36.2
2
  torch>=2.0.0
3
  gradio==5.13.2
4
  sentencepiece>=0.1.99
 
 
 
 
2
  torch>=2.0.0
3
  gradio==5.13.2
4
  sentencepiece>=0.1.99
5
+ fastapi>=0.104.1
6
+ uvicorn>=0.24.0
7
+ python-multipart>=0.0.6