File size: 1,363 Bytes
5a3ebe3
1967004
 
 
 
a169d7c
1967004
d6c8def
31cc919
a169d7c
 
d6c8def
a169d7c
 
556b1ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a169d7c
eac07db
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
import gradio as gr
import requests
#from transformers import AutoTokenizer
#tokenizer = AutoTokenizer.from_pretrained("liam168/c2-roberta-base-finetuned-dianping-chinese")
def chat(input):
    global conversation_history
    url = 'http://dark.21cnai.com:5000/api/chat'
    data = { "message": input }
    headers = {"Content-Type": "Application/json","Authorization":"Bearer kdfjwoieskdflasdnf"}
    response = f"您说:{input_text}\n"
    conversation_history += response
    response = requests.post(url, json=data, headers=headers)
    conversation_history += ”chatGPT:"+response.text
    return conversation_history

css = '''
    .input_text, .output_text {
        font-family: Arial, sans-serif;
        font-size: 16px;
    }
    .input_text:focus {
        border: 2px solid #2C7BE5;
        outline: none;
    }
    .output_text {
        background-color: #F8F9FA;
        border: 1px solid #CED4DA;
        color: #495057;
    }
    .input_button {
        background-color: #2C7BE5;
        color: white;
        font-weight: bold;
        border: none;
    }
'''

iface = gr.Interface(fn=chat, inputs=gr.inputs.Textbox(lines=3, placeholder="在此输入您的问题..."), outputs=gr.outputs.Textbox(),title="ChatGPT 对话",description="请输入您的问题,然后按回车键或单击提交。",css=css)
iface.launch(server_name="0.0.0.0")