Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import time
|
| 4 |
import os
|
| 5 |
|
| 6 |
api_key = os.getenv("apichatbotacess")
|
| 7 |
|
| 8 |
# Define the API calling function
|
| 9 |
-
def api_call(prompt, thread_id, model_name):
|
| 10 |
url = "https://multimodalcompany-dev--talent-chatbot-beta-dev-dev.modal.run"
|
| 11 |
headers = {
|
| 12 |
"key": api_key,
|
|
@@ -15,7 +14,7 @@ def api_call(prompt, thread_id, model_name):
|
|
| 15 |
data = {
|
| 16 |
"prompt": prompt,
|
| 17 |
"thread_id": thread_id,
|
| 18 |
-
"model_name": model_name,
|
| 19 |
"max_new_tokens": 4096,
|
| 20 |
"top_p": 0.95,
|
| 21 |
"temperature": 0.7,
|
|
@@ -26,7 +25,8 @@ def api_call(prompt, thread_id, model_name):
|
|
| 26 |
"topic_id": "talent-chatbot",
|
| 27 |
"persist_data": True,
|
| 28 |
"max_chat_history_tokens": 2000,
|
| 29 |
-
"max_chat_history_days": 10
|
|
|
|
| 30 |
}
|
| 31 |
response = requests.post(url, headers=headers, json=data)
|
| 32 |
return response.json()["message"]
|
|
@@ -38,10 +38,10 @@ with gr.Blocks() as demo:
|
|
| 38 |
msg = gr.Textbox(label="Your Message")
|
| 39 |
|
| 40 |
def respond(message, thread_id, chat_history, model_name):
|
| 41 |
-
bot_message = api_call(message, thread_id, model_name)
|
| 42 |
chat_history.append((message, bot_message))
|
| 43 |
return "", chat_history
|
| 44 |
|
| 45 |
-
msg.submit(respond, [msg, thread_id_input,
|
| 46 |
|
| 47 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
api_key = os.getenv("apichatbotacess")
|
| 6 |
|
| 7 |
# Define the API calling function
|
| 8 |
+
def api_call(prompt, thread_id, model_name, chat_history):
|
| 9 |
url = "https://multimodalcompany-dev--talent-chatbot-beta-dev-dev.modal.run"
|
| 10 |
headers = {
|
| 11 |
"key": api_key,
|
|
|
|
| 14 |
data = {
|
| 15 |
"prompt": prompt,
|
| 16 |
"thread_id": thread_id,
|
| 17 |
+
"model_name": model_name,
|
| 18 |
"max_new_tokens": 4096,
|
| 19 |
"top_p": 0.95,
|
| 20 |
"temperature": 0.7,
|
|
|
|
| 25 |
"topic_id": "talent-chatbot",
|
| 26 |
"persist_data": True,
|
| 27 |
"max_chat_history_tokens": 2000,
|
| 28 |
+
"max_chat_history_days": 10,
|
| 29 |
+
"chat_history": chat_history # Include chat history
|
| 30 |
}
|
| 31 |
response = requests.post(url, headers=headers, json=data)
|
| 32 |
return response.json()["message"]
|
|
|
|
| 38 |
msg = gr.Textbox(label="Your Message")
|
| 39 |
|
| 40 |
def respond(message, thread_id, chat_history, model_name):
|
| 41 |
+
bot_message = api_call(message, thread_id, model_name, chat_history)
|
| 42 |
chat_history.append((message, bot_message))
|
| 43 |
return "", chat_history
|
| 44 |
|
| 45 |
+
msg.submit(respond, [msg, thread_id_input, gr.State([]), model_name], [msg, chatbot])
|
| 46 |
|
| 47 |
+
demo.launch()
|