Midna1980 commited on
Commit
07578df
·
verified ·
1 Parent(s): 555e1bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -1,22 +1,25 @@
1
- from fastapi import FastAPI
2
- from pydantic import BaseModel
3
  from transformers import pipeline
4
 
5
- # Création de l'app FastAPI
6
- app = FastAPI()
7
-
8
- # Chargement du modèle Hugging Face (T5 pour text2text)
9
  model = pipeline("text2text-generation", model="t5-small")
10
 
11
- # Définition du format d'entrée
12
- class Prompt(BaseModel):
13
- prompt: str
14
-
15
- # Endpoint d'API
16
- @app.post("/generate")
17
- def generate_text(prompt: Prompt):
18
  try:
19
- output = model(prompt.prompt, max_length=100)
20
- return {"result": output[0]["generated_text"]}
21
  except Exception as e:
22
- return {"error": str(e)}
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
 
2
  from transformers import pipeline
3
 
4
+ # Création du pipeline de génération
 
 
 
5
  model = pipeline("text2text-generation", model="t5-small")
6
 
7
+ # Fonction d'inférence
8
+ def chat(prompt):
 
 
 
 
 
9
  try:
10
+ result = model(prompt, max_length=100)
11
+ return result[0]["generated_text"]
12
  except Exception as e:
13
+ return f"Erreur : {str(e)}"
14
+
15
+ # Interface Gradio
16
+ interface = gr.Interface(
17
+ fn=chat,
18
+ inputs=gr.Textbox(lines=2, placeholder="Écris quelque chose..."),
19
+ outputs="text",
20
+ title="T5 Chatbot",
21
+ description="API de génération avec T5-small"
22
+ )
23
+
24
+ # Lancement du serveur Gradio
25
+ interface.launch(server_name="0.0.0.0", server_port=7860)