Spaces:
Sleeping
Sleeping
import gradio as gr | |
import random | |
import time | |
import requests | |
API_URL = "https://www.llama2.ai/api" | |
def send_request(question: str): | |
payload = { | |
"prompt": "[INST] QUESTION [/INST]".replace("QUESTION",question), | |
"version": "2796ee9483c3fd7aa2e171d38f4ca12251a30609463dcfd4cd76703f22e96cdf", | |
"systemPrompt": "You are a helpful assistant", | |
"temperature": 0.75, | |
"topP": 0.9, | |
"maxTokens": 800 | |
} | |
r = requests.post(API_URL, json=payload) | |
if r.status_code == 200: | |
return r.content.decode("utf-8") | |
return "Sorry, I couldn't answer that question (network error)" | |
with gr.Blocks() as demo: | |
chatbot = gr.Chatbot() | |
msg = gr.Textbox() | |
clear = gr.ClearButton([msg, chatbot]) | |
def respond(message, chat_history): | |
bot_message = send_request(question=message) | |
chat_history.append((message, bot_message)) | |
time.sleep(2) | |
return "", chat_history | |
msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
if __name__ == "__main__": | |
demo.launch() |