File size: 1,878 Bytes
0211540
 
 
 
 
 
a3db5b8
0211540
 
 
 
 
 
 
 
d227bc9
 
 
 
 
 
 
 
 
0211540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a3db5b8
d227bc9
 
0211540
 
 
 
 
 
 
d227bc9
0211540
645f6ab
73ef389
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import logging
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.info("Loaded " + __name__)

import gradio as gr
import random
import time
import requests
import json
import uuid

logger.info(100*"#")
logger.info("Initializing gradio!")

get_window_url_params = """
    function(text_input, url_params) {
        console.log(text_input, url_params);
        const params = new URLSearchParams(window.location.search);
        url_params = Object.fromEntries(params);
        return [text_input, url_params];
        }
    """
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    import os
    import requests
    import json
    import uuid
    USER=100
    SESS_ID=str(uuid.uuid1())

    url="http://ds-lang-server:8777/v1/user_conv"
    CONV_API=os.environ.get("CONV_API",url)
    def call_api(user_input,user_id,session_id):

        url = CONV_API
    
        payload = json.dumps({
        "user_id": USER,
        "session_id":SESS_ID,
        "user_input": user_input
        })

        headers = {
        'accept': 'application/json',
        'Content-Type': 'application/json',
        'Authorization':os.environ.get('AUTH_TOKEN', None)
        }
    
        response = requests.request("POST", url, headers=headers, data=payload)
        ret=response.json()
        return ret['result']

    def respond(message, chat_history,url_params):
        print("params",url_params)
        bot_message=call_api(message,12,"xyz")
        chat_history.append((message, bot_message))
        return "", chat_history
        
    chatbot = gr.Chatbot(label='Jivi')
    msg = gr.Textbox(label='Patient')
    clear = gr.ClearButton([msg, chatbot])
    msg.submit(respond, [msg, chatbot,url_params], [msg, chatbot],_js=get_window_url_params)
    

demo.launch(auth=(os.environ.get("USER","demo"), os.environ.get("PASSWORD","demo")))