Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,25 @@
|
|
| 1 |
-
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
# Création de
|
| 6 |
-
app = FastAPI()
|
| 7 |
-
|
| 8 |
-
# Chargement du modèle Hugging Face (T5 pour text2text)
|
| 9 |
model = pipeline("text2text-generation", model="t5-small")
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
prompt: str
|
| 14 |
-
|
| 15 |
-
# Endpoint d'API
|
| 16 |
-
@app.post("/generate")
|
| 17 |
-
def generate_text(prompt: Prompt):
|
| 18 |
try:
|
| 19 |
-
|
| 20 |
-
return
|
| 21 |
except Exception as e:
|
| 22 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|