gpt2 / app.py
Dofla's picture
create app.py
db23b5c verified
raw
history blame contribute delete
No virus
1.93 kB
import gradio as gr
from datetime import datetime
from tensorflow.keras.models import load_model, save_model
gpt2_lm = load_model('my_model.keras')
# Définir votre thème personnalisé
theme_chat = gr.themes.Soft(
primary_hue="teal",
secondary_hue="cyan",
neutral_hue="slate",
)
custom_css="""
@import url('https://fonts.googleapis.com/css2?family=Tangerine:wght@700&display=swap');
body {
margin: 0;
padding: 0;
}
.container {
width: 80%;
margin: 0 auto;
}
h1 {
font-size: 3em;
margin-top: 20px;
font-family: 'Tangerine', serif;
}
p {
font-size: 1.5em;
color: turquoise;
text-align: center;
}
.textbox {
width: 80%;
margin: 20px auto;
padding: 10px;
font-size: 1.2em;
}
.chatbox {
border: 1px solid #ccc;
padding: 20px;
margin-top: 20px;
border-radius: 8px;
}
.btn {
display: inline-block;
padding: 10px 20px;
font-size: 1em;
text-align: center;
text-decoration: none;
border-radius: 5px;
cursor: pointer;
}
"""
def chat_bot_response(message, history):
message = message.replace("?","").strip()
# le paramètre max_length est à enlever pour l'instant
return gpt2_lm.generate(message)
# Créer l'interface Gradio avec le thème personnalisé
interface = gr.ChatInterface(
chat_bot_response,
chatbot=gr.Chatbot(height=500),
textbox=gr.Textbox(placeholder="Posez moi une question sur le CoronaVirus", container=False, scale=7),
title="Vit'IA",
description="Posez une question à Vit'IA :",
examples=["The covid is a ?", "Symptoms of the covid are ?", "The best way to protect yourself from covid is to ?"],
cache_examples=False,
retry_btn="Générer une nouvelle réponse",
undo_btn="Supprimer la réponse précédente",
clear_btn="Effacer",
submit_btn="Envoyer",
css= custom_css,
theme=theme_chat
)
# Lancer l'interface
interface.launch()