Spaces:
Runtime error
Runtime error
Update api/main.py
Browse files- api/main.py +0 -6
api/main.py
CHANGED
|
@@ -1,24 +1,18 @@
|
|
| 1 |
-
#main.py
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
from pydantic import BaseModel
|
| 4 |
import google.generativeai as genai
|
| 5 |
|
| 6 |
-
# Cấu hình FastAPI
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
# Cấu hình API key cho Gemini
|
| 10 |
genai.configure(api_key='AIzaSyBvhkco5aRtkqEyPFFaTKaaDmJkgU12MJU')
|
| 11 |
llm_model = genai.GenerativeModel('gemini-1.5-pro')
|
| 12 |
|
| 13 |
-
# Khai báo request body để nhận nội dung từ Streamlit
|
| 14 |
class InputText(BaseModel):
|
| 15 |
text: str
|
| 16 |
|
| 17 |
-
# Route xử lý yêu cầu từ Streamlit
|
| 18 |
@app.post("/generate")
|
| 19 |
async def generate_text(input_text: InputText):
|
| 20 |
try:
|
| 21 |
-
# Gọi API Gemini
|
| 22 |
response = llm_model.generate_content(input_text.text)
|
| 23 |
return {"generated_text": response.text}
|
| 24 |
except Exception as e:
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
|
|
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
|
|
| 7 |
genai.configure(api_key='AIzaSyBvhkco5aRtkqEyPFFaTKaaDmJkgU12MJU')
|
| 8 |
llm_model = genai.GenerativeModel('gemini-1.5-pro')
|
| 9 |
|
|
|
|
| 10 |
class InputText(BaseModel):
|
| 11 |
text: str
|
| 12 |
|
|
|
|
| 13 |
@app.post("/generate")
|
| 14 |
async def generate_text(input_text: InputText):
|
| 15 |
try:
|
|
|
|
| 16 |
response = llm_model.generate_content(input_text.text)
|
| 17 |
return {"generated_text": response.text}
|
| 18 |
except Exception as e:
|