create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
|
| 4 |
+
from tensorflow.keras.models import load_model, save_model
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
gpt2_lm = load_model('my_model.keras')
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# Définir votre thème personnalisé
|
| 11 |
+
theme_chat = gr.themes.Soft(
|
| 12 |
+
primary_hue="teal",
|
| 13 |
+
secondary_hue="cyan",
|
| 14 |
+
neutral_hue="slate",
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
custom_css="""
|
| 18 |
+
@import url('https://fonts.googleapis.com/css2?family=Tangerine:wght@700&display=swap');
|
| 19 |
+
|
| 20 |
+
body {
|
| 21 |
+
margin: 0;
|
| 22 |
+
padding: 0;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.container {
|
| 26 |
+
width: 80%;
|
| 27 |
+
margin: 0 auto;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
h1 {
|
| 31 |
+
font-size: 3em;
|
| 32 |
+
margin-top: 20px;
|
| 33 |
+
font-family: 'Tangerine', serif;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
p {
|
| 37 |
+
font-size: 1.5em;
|
| 38 |
+
color: turquoise;
|
| 39 |
+
text-align: center;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
.textbox {
|
| 43 |
+
width: 80%;
|
| 44 |
+
margin: 20px auto;
|
| 45 |
+
padding: 10px;
|
| 46 |
+
font-size: 1.2em;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.chatbox {
|
| 50 |
+
border: 1px solid #ccc;
|
| 51 |
+
padding: 20px;
|
| 52 |
+
margin-top: 20px;
|
| 53 |
+
border-radius: 8px;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.btn {
|
| 57 |
+
display: inline-block;
|
| 58 |
+
padding: 10px 20px;
|
| 59 |
+
font-size: 1em;
|
| 60 |
+
text-align: center;
|
| 61 |
+
text-decoration: none;
|
| 62 |
+
border-radius: 5px;
|
| 63 |
+
cursor: pointer;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def chat_bot_response(message, history):
|
| 70 |
+
message = message.replace("?","").strip()
|
| 71 |
+
# le paramètre max_length est à enlever pour l'instant
|
| 72 |
+
return gpt2_lm.generate(message)
|
| 73 |
+
|
| 74 |
+
# Créer l'interface Gradio avec le thème personnalisé
|
| 75 |
+
interface = gr.ChatInterface(
|
| 76 |
+
chat_bot_response,
|
| 77 |
+
chatbot=gr.Chatbot(height=500),
|
| 78 |
+
textbox=gr.Textbox(placeholder="Posez moi une question sur le CoronaVirus", container=False, scale=7),
|
| 79 |
+
title="Vit'IA",
|
| 80 |
+
description="Posez une question à Vit'IA :",
|
| 81 |
+
examples=["The covid is a ?", "Symptoms of the covid are ?", "The best way to protect yourself from covid is to ?"],
|
| 82 |
+
cache_examples=False,
|
| 83 |
+
retry_btn="Générer une nouvelle réponse",
|
| 84 |
+
undo_btn="Supprimer la réponse précédente",
|
| 85 |
+
clear_btn="Effacer",
|
| 86 |
+
submit_btn="Envoyer",
|
| 87 |
+
css= custom_css,
|
| 88 |
+
theme=theme_chat
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
# Lancer l'interface
|
| 92 |
+
interface.launch()
|