slothdev commited on
Commit
f8e76bd
·
1 Parent(s): 76a1f96
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -1,16 +1,26 @@
1
  from fastapi import FastAPI
 
2
  from transformers import pipeline
3
 
4
  # Create a new FastAPI app instance
5
  app = FastAPI()
6
 
 
 
 
 
 
 
 
 
 
7
  # Initialize the text generation pipeline
8
  pipe = pipeline("text2text-generation", model="google/flan-t5-small")
9
 
10
  # Define a root path to verify the server is running
11
  @app.get("/")
12
  def read_root():
13
- return {"message": "Welcome to the FastAPI application. Use /generate to generate text 2."}
14
 
15
  # Define a function to handle the GET request at `/generate`
16
  @app.get("/generate")
 
1
  from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
  from transformers import pipeline
4
 
5
  # Create a new FastAPI app instance
6
  app = FastAPI()
7
 
8
+ # Add CORS middleware
9
+ app.add_middleware(
10
+ CORSMiddleware,
11
+ allow_origins=["*"], # Allow all origins
12
+ allow_credentials=True,
13
+ allow_methods=["*"], # Allow all methods
14
+ allow_headers=["*"], # Allow all headers
15
+ )
16
+
17
  # Initialize the text generation pipeline
18
  pipe = pipeline("text2text-generation", model="google/flan-t5-small")
19
 
20
  # Define a root path to verify the server is running
21
  @app.get("/")
22
  def read_root():
23
+ return {"message": "Welcome to the FastAPI application. Use /generate to generate text."}
24
 
25
  # Define a function to handle the GET request at `/generate`
26
  @app.get("/generate")