File size: 1,837 Bytes
5a3ebe3
1967004
 
 
45b560c
1967004
dc1c699
1967004
d6c8def
31cc919
89086b1
d6c8def
45b560c
fc55914
a169d7c
556b1ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45b560c
 
 
 
 
 
 
 
 
 
 
 
 
 
556b1ad
 
45b560c
 
ee55769
45b560c
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr
import requests
#from transformers import AutoTokenizer
#tokenizer = AutoTokenizer.from_pretrained("liam168/c2-roberta-base-finetuned-dianping-chinese")
conversation_history = ""
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"}
    user_message = f'<span class="user">您说:{input}</span><br>'
    response = requests.post(url, json=data, headers=headers)
    bot_message = f'<span class="chatbot">ChatGPT:{response.text}</span><br>'
    conversation_history = user_message + bot_message
    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;
    }
    .user {
        color: blue;
    }
    .chatbot {
        color: green;
    }
    .container {
        display: flex;
        flex-direction: column;
        height: 100%;
    }
    .output_section {
        flex-grow: 1;
    }
'''

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