Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
model_name = "gpt2-large"
|
4 |
+
|
5 |
+
inference = InferenceClient(
|
6 |
+
model=model_name,
|
7 |
+
# token=os.environ['HF_API_KEY']
|
8 |
+
)
|
9 |
+
|
10 |
+
def respond(message, chat_history, max_tokens=32):
|
11 |
+
bot_message = inference.text_generation(
|
12 |
+
prompt=message,
|
13 |
+
max_new_tokens=max_tokens,
|
14 |
+
stop_sequences=['.'], # Stop generating tokens if a member of stop_sequences is generated
|
15 |
+
)
|
16 |
+
chat_history.append((message, f"{bot_message}."))
|
17 |
+
return "", chat_history
|
18 |
+
|
19 |
+
with gr.Blocks(
|
20 |
+
title='RugbyXpert',
|
21 |
+
# theme='sudeepshouche/minimalist', # https://www.gradio.app/guides/theming-guide
|
22 |
+
) as demo:
|
23 |
+
gr.Markdown(
|
24 |
+
"""
|
25 |
+
# RugbyXpert
|
26 |
+
"""
|
27 |
+
)
|
28 |
+
chatbot = gr.Chatbot(
|
29 |
+
height=310, # just to fit the notebook
|
30 |
+
)
|
31 |
+
msg = gr.Textbox(label="Pose-moi une question sur le rugby pendant la saison 2022-2023")
|
32 |
+
with gr.Row():
|
33 |
+
with gr.Column():
|
34 |
+
btn = gr.Button("Submit", variant="primary")
|
35 |
+
with gr.Column():
|
36 |
+
clear = gr.ClearButton(components=[msg, chatbot], value="Clear console")
|
37 |
+
gr.Examples([
|
38 |
+
"Tu peux me donner le 21 de Vannes lors du match les opposant à Aurillac du vendredi 24 février 2023 ?",
|
39 |
+
"Tu peux me retrouver le score final du match opposant Soyaux-Angoulême à Grenoble le vendredi 17 mars 2023 ?",
|
40 |
+
"Dis-moi le score final du match opposant Vannes à Aurillac le vendredi 24 février 2023 ?",
|
41 |
+
], [msg])
|
42 |
+
|
43 |
+
btn.click(respond, inputs=[msg, chatbot], outputs=[msg, chatbot])
|
44 |
+
msg.submit(respond, inputs=[msg, chatbot], outputs=[msg, chatbot]) #Press enter to submit
|
45 |
+
|
46 |
+
demo.launch()
|