huedaya commited on
Commit
f410bac
·
verified ·
1 Parent(s): 714866c

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +11 -4
main.py CHANGED
@@ -1,11 +1,19 @@
1
- from fastapi import FastAPI
 
2
  from pydantic import BaseModel
3
  from huggingface_hub import InferenceClient
4
- import uvicorn
5
-
6
 
7
  app = FastAPI()
8
 
 
 
 
 
 
 
 
 
 
9
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
10
 
11
  class Item(BaseModel):
@@ -46,4 +54,3 @@ def generate(item: Item):
46
  @app.post("/generate/")
47
  async def generate_text(item: Item):
48
  return {"response": generate(item)}
49
-
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
  from pydantic import BaseModel
4
  from huggingface_hub import InferenceClient
 
 
5
 
6
  app = FastAPI()
7
 
8
+ # Allow all CORS
9
+ app.add_middleware(
10
+ CORSMiddleware,
11
+ allow_origins=["*"],
12
+ allow_credentials=True,
13
+ allow_methods=["*"],
14
+ allow_headers=["*"],
15
+ )
16
+
17
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
18
 
19
  class Item(BaseModel):
 
54
  @app.post("/generate/")
55
  async def generate_text(item: Item):
56
  return {"response": generate(item)}