ULMER Louis (T0240644)
commited on
Commit
·
e361e2e
1
Parent(s):
5360998
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from utils import generate_response, emb2info, pre_prompt, get_embedding
|
4 |
+
os.environ['NO_PROXY'] = '127.0.0.1'
|
5 |
+
print(os.getcwd())
|
6 |
+
|
7 |
+
def predict(user_input, history=[]):
|
8 |
+
# tokenize the new input sentence
|
9 |
+
emb_user = get_embedding(user_input)
|
10 |
+
info_to_add, retrieval_text = emb2info(emb_user)
|
11 |
+
|
12 |
+
response = generate_response(pre_prompt + info_to_add + \
|
13 |
+
"\n \n User : " + user_input + "\n Chat bot :")
|
14 |
+
|
15 |
+
|
16 |
+
history.append((user_input,response))
|
17 |
+
#response = [(user_input,response)]
|
18 |
+
return history, history
|
19 |
+
|
20 |
+
|
21 |
+
with gr.Blocks() as app:
|
22 |
+
gr.Markdown(
|
23 |
+
"## Bienvenue sur l'interface demo de SARA "
|
24 |
+
)
|
25 |
+
|
26 |
+
logo_URL = "file/static/logo_sara.png"
|
27 |
+
image = "<center> <img src= {} width=150px></center>".format(logo_URL)
|
28 |
+
|
29 |
+
gr.HTML(image)
|
30 |
+
|
31 |
+
chatbot = gr.Chatbot()
|
32 |
+
state = gr.State([])
|
33 |
+
|
34 |
+
with gr.Row():
|
35 |
+
txt = gr.Textbox(show_label=False, placeholder="Entrez votre question").style(container=False)
|
36 |
+
|
37 |
+
gr.Examples(
|
38 |
+
examples=[
|
39 |
+
"Who should I call if I struggle with the GPU ? ",
|
40 |
+
"Who can I call if I need help on diffusion models ? ",
|
41 |
+
"Qui peut m'aider en NLP ?",
|
42 |
+
"Qui est un specialiste de la segmentation d'image dans l'equipe ?",
|
43 |
+
],
|
44 |
+
inputs=txt,
|
45 |
+
)
|
46 |
+
|
47 |
+
txt.submit(predict, [txt, state], [chatbot, state])
|
48 |
+
|
49 |
+
|
50 |
+
|
51 |
+
gr.HTML(
|
52 |
+
"️<center> Created with ❤️ by @louis_ulmer & @aurelien_lac"
|
53 |
+
)
|
54 |
+
|
55 |
+
app.launch(share=True, auth=("admin", "pass"))
|