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):
url = 'http://dark.21cnai.com:5000/api/chat'
data = { "message": input }
headers = {"Content-Type": "Application/json","Authorization":"Bearer kdfjwoieskdflasdnf"}
user_message = f'您说:{input_text}
'
response = requests.post(url, json=data, headers=headers)
bot_message = f'ChatGPT:{response.text}
'
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,
inputs=gr.inputs.Textbox(lines=3, placeholder="在此输入您的问题..."),
outputs=gr.outputs.HTML(),
title="ChatGPT 对话",
description="请输入您的问题,然后按回车键或单击提交。",
layout="vertical",
css=css)
iface.launch(server_name="0.0.0.0")