Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,34 @@
|
|
1 |
-
from transformers import
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
# Fonction de génération
|
8 |
def generate_text(prompt):
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
# Interface Gradio
|
13 |
-
|
14 |
fn=generate_text,
|
15 |
-
inputs="
|
16 |
outputs="text",
|
17 |
-
title="
|
18 |
-
description="Tapez une phrase, et l’IA continue avec GPT-2 !"
|
19 |
)
|
20 |
|
21 |
-
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Nom du modèle léger français
|
5 |
+
model_name = "dbddv01/gpt2-french-small"
|
6 |
+
|
7 |
+
# Charger tokenizer et modèle
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
|
|
|
11 |
def generate_text(prompt):
|
12 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
13 |
+
outputs = model.generate(
|
14 |
+
inputs.input_ids,
|
15 |
+
max_length=150,
|
16 |
+
do_sample=True,
|
17 |
+
temperature=0.7,
|
18 |
+
top_p=0.9,
|
19 |
+
top_k=50,
|
20 |
+
repetition_penalty=1.1,
|
21 |
+
pad_token_id=tokenizer.eos_token_id
|
22 |
+
)
|
23 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
24 |
|
25 |
+
# Interface simple avec Gradio
|
26 |
+
iface = gr.Interface(
|
27 |
fn=generate_text,
|
28 |
+
inputs=gr.Textbox(lines=3, placeholder="Écris ton texte ici..."),
|
29 |
outputs="text",
|
30 |
+
title="Générateur de texte libre français léger"
|
|
|
31 |
)
|
32 |
|
33 |
+
if __name__ == "__main__":
|
34 |
+
iface.launch()
|