File size: 1,330 Bytes
15c1a0b
a826fde
 
5a15a21
a826fde
6cf7845
 
a826fde
 
3365484
a826fde
6cf7845
a826fde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import requests
import time
import os

api_key = os.getenv("apichatbotacess")

# Define the API calling function
def api_call(prompt, thread_id):
    url = "https://multimodalcompany-dev--talent-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)