Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,59 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
d.launch()
|
|
|
1 |
+
import logging
|
2 |
+
logging.basicConfig()
|
3 |
+
logger = logging.getLogger(__name__)
|
4 |
+
logger.setLevel(logging.DEBUG)
|
5 |
+
logger.info("Loaded " + __name__)
|
6 |
+
|
7 |
import gradio as gr
|
8 |
+
import random
|
9 |
+
import time
|
10 |
+
import requests
|
11 |
+
import json
|
12 |
+
import uuid
|
13 |
+
|
14 |
+
logger.info(100*"#")
|
15 |
+
logger.info("Initializing gradio!")
|
16 |
+
|
17 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
18 |
+
import os
|
19 |
+
import requests
|
20 |
+
import json
|
21 |
+
import uuid
|
22 |
+
USER=100
|
23 |
+
SESS_ID=str(uuid.uuid1())
|
24 |
+
|
25 |
+
url="http://ds-lang-server:8777/v1/user_conv"
|
26 |
+
url =
|
27 |
+
CONV_API=os.environ.get("CONV_API",url)
|
28 |
+
def call_api(user_input,user_id,session_id):
|
29 |
+
|
30 |
+
url = CONV_API
|
31 |
+
|
32 |
+
payload = json.dumps({
|
33 |
+
"user_id": USER,
|
34 |
+
"session_id":SESS_ID,
|
35 |
+
"user_input": user_input
|
36 |
+
})
|
37 |
+
|
38 |
+
headers = {
|
39 |
+
'accept': 'application/json',
|
40 |
+
'Content-Type': 'application/json',
|
41 |
+
'Authorization':os.environ.get('AUTH_TOKEN', None)
|
42 |
+
}
|
43 |
+
|
44 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
45 |
+
ret=response.json()
|
46 |
+
return ret['result']
|
47 |
|
48 |
+
def respond(message, chat_history):
|
49 |
+
bot_message=call_api(message,12,"xyz")
|
50 |
+
chat_history.append((message, bot_message))
|
51 |
+
return "", chat_history
|
52 |
+
|
53 |
+
chatbot = gr.Chatbot(label='Jivi')
|
54 |
+
msg = gr.Textbox(label='Patient')
|
55 |
+
clear = gr.ClearButton([msg, chatbot])
|
56 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
57 |
+
|
58 |
|
59 |
+
demo.launch()
|
|