File size: 1,026 Bytes
60df86f
 
 
 
 
 
 
 
 
 
 
69d661b
60df86f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()