Spaces:
Runtime error
Runtime error
| 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): | |
| #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') | |
| #url_params = gr.JSON({}, visible=False, label="URL Params") | |
| clear = gr.ClearButton([msg, chatbot]) | |
| msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
| demo.launch(auth=(os.environ.get("USER","demo"), os.environ.get("PASSWORD","demo"))) | |