Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
import time | |
import os | |
api_key = os.getenv("apismbcchatbotacess") | |
# Define the API calling function | |
def api_call(prompt, thread_id): | |
url = "https://multimodalcompany-dev--smbc-chatbot-dev.modal.run" | |
headers = { | |
"key": api_key, | |
"Content-Type": "application/json" | |
} | |
data = { | |
"prompt": prompt, | |
"thread_id": thread_id, | |
"max_new_tokens": 4096, | |
"top_p": 0.95, | |
"temperature": 0.7, | |
"repetition_penalty": 1.15, | |
"do_sample": False, | |
"stream": False, | |
"user_id": "talent-demo-user", | |
"topic_id": "talent-chatbot", | |
"persist_data": True, | |
"max_chat_history_tokens": 2000, | |
"max_chat_history_days": 10 | |
} | |
response = requests.post(url, headers=headers, json=data) | |
return response.json()["r1"] | |
with gr.Blocks() as demo: | |
thread_id_input = gr.Textbox(label="Enter Thread ID", placeholder="Thread ID", lines=1) | |
chatbot = gr.Chatbot() | |
msg = gr.Textbox(label="Your Message") | |
def respond(message, thread_id, chat_history): | |
bot_message = api_call(message, thread_id) | |
chat_history.append((message, bot_message)) | |
return "", chat_history | |
msg.submit(respond, [msg, thread_id_input, chatbot], [msg, chatbot]) | |
demo.launch(share=True) |