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

Update CORS configuration for GitHub Pages integration

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -3,13 +3,13 @@ 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=["*"],
@@ -41,7 +41,7 @@ def generate_clinical_report(input_text):
41
  # Decode and return the generated report
42
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
43
 
44
- # Create Gradio interface with updated styling
45
  demo = gr.Interface(
46
  fn=generate_clinical_report,
47
  inputs=[
@@ -70,12 +70,23 @@ demo = gr.Interface(
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)
 
 
 
 
 
 
 
 
 
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=["*"],
 
41
  # Decode and return the generated report
42
  return tokenizer.decode(outputs[0], skip_special_tokens=True)
43
 
44
+ # Create Gradio interface with queue
45
  demo = gr.Interface(
46
  fn=generate_clinical_report,
47
  inputs=[
 
70
  #input-box { background-color: #f6f6f6; }
71
  #output-box { background-color: #f0f7ff; }
72
  """,
73
+ flagging_mode="never"
74
  )
75
 
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
+ )