Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import joblib
|
| 4 |
+
#charger le model et le tokenizer
|
| 5 |
+
model_=joblib.load('model.joblib')
|
| 6 |
+
tokenizer_=joblib.load('tokenizer.joblib')
|
| 7 |
+
def blagueur(prompt):
|
| 8 |
+
inputs = tokenizer_(prompt, return_tensors="pt", truncation=True, padding="max_length", max_length=128)
|
| 9 |
+
outputs = model_.generate(
|
| 10 |
+
input_ids=inputs["input_ids"],
|
| 11 |
+
attention_mask=inputs["attention_mask"],
|
| 12 |
+
max_length=64,
|
| 13 |
+
num_beams=5,
|
| 14 |
+
do_sample=True,
|
| 15 |
+
temperature=0.9
|
| 16 |
+
)
|
| 17 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 18 |
+
|
| 19 |
+
# Configuration de l'interface Gradio
|
| 20 |
+
demo = gr.Interface(
|
| 21 |
+
fn=blagueur,
|
| 22 |
+
inputs=gr.Textbox(lines=2, placeholder="Demandez-moi une blague..."),
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="Chatbot Comique",
|
| 25 |
+
description="Un chatbot qui raconte des blagues. Demandez-lui une blague et il vous fera rire!",
|
| 26 |
+
examples=[
|
| 27 |
+
["Raconte-moi une blague"],
|
| 28 |
+
["Dis-moi une blague sur les animaux"],
|
| 29 |
+
["Blague sur les informaticiens"]
|
| 30 |
+
],
|
| 31 |
+
theme='shivi/calm_seafoam'
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
demo.launch()
|