clarkchan commited on
Commit
45b560c
1 Parent(s): a169d7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -2,15 +2,15 @@ import gradio as gr
2
  import requests
3
  #from transformers import AutoTokenizer
4
  #tokenizer = AutoTokenizer.from_pretrained("liam168/c2-roberta-base-finetuned-dianping-chinese")
 
5
  def chat(input):
6
- global conversation_history
7
  url = 'http://dark.21cnai.com:5000/api/chat'
8
  data = { "message": input }
9
  headers = {"Content-Type": "Application/json","Authorization":"Bearer kdfjwoieskdflasdnf"}
10
- response = f"您说:{input_text}\n"
11
- conversation_history += response
12
  response = requests.post(url, json=data, headers=headers)
13
- conversation_history += ”chatGPT:"+response.text
 
14
  return conversation_history
15
 
16
  css = '''
@@ -33,7 +33,27 @@ css = '''
33
  font-weight: bold;
34
  border: none;
35
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  '''
37
 
38
- iface = gr.Interface(fn=chat, inputs=gr.inputs.Textbox(lines=3, placeholder="在此输入您的问题..."), outputs=gr.outputs.Textbox(),title="ChatGPT 对话",description="请输入您的问题,然后按回车键或单击提交。",css=css)
 
 
 
 
 
 
39
  iface.launch(server_name="0.0.0.0")
 
2
  import requests
3
  #from transformers import AutoTokenizer
4
  #tokenizer = AutoTokenizer.from_pretrained("liam168/c2-roberta-base-finetuned-dianping-chinese")
5
+ conversation_history = ""
6
  def chat(input):
 
7
  url = 'http://dark.21cnai.com:5000/api/chat'
8
  data = { "message": input }
9
  headers = {"Content-Type": "Application/json","Authorization":"Bearer kdfjwoieskdflasdnf"}
10
+ user_message = f'<span class="user">您说:{input_text}</span><br>'
 
11
  response = requests.post(url, json=data, headers=headers)
12
+ bot_message = f'<span class="chatbot">ChatGPT:{response.text}</span><br>'
13
+ conversation_history += user_message + bot_message
14
  return conversation_history
15
 
16
  css = '''
 
33
  font-weight: bold;
34
  border: none;
35
  }
36
+ .user {
37
+ color: blue;
38
+ }
39
+ .chatbot {
40
+ color: green;
41
+ }
42
+ .container {
43
+ display: flex;
44
+ flex-direction: column;
45
+ height: 100%;
46
+ }
47
+ .output_section {
48
+ flex-grow: 1;
49
+ }
50
  '''
51
 
52
+ iface = gr.Interface(fn=chat,
53
+ inputs=gr.inputs.Textbox(lines=3, placeholder="在此输入您的问题..."),
54
+ outputs=gr.outputs.HTML(),
55
+ title="ChatGPT 对话",
56
+ description="请输入您的问题,然后按回车键或单击提交。",
57
+ layout="vertical",
58
+ css=css)
59
  iface.launch(server_name="0.0.0.0")