Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import Dict
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Utilise un petit modèle pour que ça fonctionne même sur les GPUs limités
|
| 9 |
+
llm = pipeline("text2text-generation", model="google/flan-t5-base", max_new_tokens=300)
|
| 10 |
+
|
| 11 |
+
class AgentInput(BaseModel):
|
| 12 |
+
prompt: str
|
| 13 |
+
data: Dict = {}
|
| 14 |
+
|
| 15 |
+
@app.post("/analyze")
|
| 16 |
+
async def analyze(input: AgentInput):
|
| 17 |
+
full_prompt = f"Voici des données JSON :\n{input.data}\n\nQuestion : {input.prompt}\nRéponse :"
|
| 18 |
+
result = llm(full_prompt)[0]["generated_text"]
|
| 19 |
+
return {"response": result}
|