Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Crée le générateur de texte avec un modèle francophone
|
| 5 |
+
generator = pipeline("text-generation", model="asi/gpt-fr-cased-small")
|
| 6 |
+
|
| 7 |
+
# Fonction qui génère du texte à partir du prompt utilisateur
|
| 8 |
+
def repondre(prompt):
|
| 9 |
+
result = generator(
|
| 10 |
+
prompt,
|
| 11 |
+
max_length=60,
|
| 12 |
+
num_return_sequences=1,
|
| 13 |
+
temperature=0.9,
|
| 14 |
+
top_k=50,
|
| 15 |
+
repetition_penalty=1.2
|
| 16 |
+
)
|
| 17 |
+
return result[0]["generated_text"]
|
| 18 |
+
|
| 19 |
+
# Interface Gradio
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=repondre,
|
| 22 |
+
inputs="text",
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="Chat avec GPT-2 (version française 🧠🇫🇷)",
|
| 25 |
+
description="Pose une question ou commence une phrase, le modèle complète !"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Lancement
|
| 29 |
+
interface.launch()
|