yym68686 commited on
Commit
56bc861
·
1 Parent(s): 9d1ddde

update app

Browse files
Files changed (3) hide show
  1. .gitignore +4 -0
  2. app.py +42 -4
  3. requirements.txt +2 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ __pycache__/
2
+ .DS_Store
3
+ .vscode
4
+ .env
app.py CHANGED
@@ -1,5 +1,43 @@
1
  import gradio as gr
2
- def print_text(text):
3
- return "Hello World, " + text
4
- interface = gr.Interface(fn=print_text, inputs="text", outputs="text")
5
- interface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+
3
+ import os
4
+ from datetime import datetime
5
+ from ModelMerge.utils import prompt
6
+ from ModelMerge.models import chatgpt
7
+ LANGUAGE = os.environ.get('LANGUAGE', 'Simplified Chinese')
8
+ GPT_ENGINE = os.environ.get('GPT_ENGINE', 'gpt-4-turbo-2024-04-09')
9
+ API = os.environ.get('API', None)
10
+ Current_Date = datetime.now().strftime("%Y-%m-%d")
11
+ systemprompt = os.environ.get('SYSTEMPROMPT', prompt.system_prompt.format(LANGUAGE, Current_Date))
12
+ chatgptbot = chatgpt(api_key=f"{API}", engine=GPT_ENGINE, system_prompt=systemprompt)
13
+
14
+
15
+ with gr.Blocks(fill_height=True) as demo:
16
+ with gr.Column():
17
+ chatbot = gr.Chatbot(show_label=False, elem_id="chatbox", scale=2) # 设置聊天框高度
18
+ with gr.Row():
19
+ msg = gr.Textbox(placeholder="输入你的问题...", elem_id="inputbox", scale=10)
20
+ clear = gr.Button("清除", elem_id="clearbutton")
21
+
22
+ # 用户输入处理函数,记录用户的问题
23
+ def user(user_message, history):
24
+ return "", history + [[user_message, None]]
25
+
26
+ # 机器人回答函数,根据用户的问题生成回答
27
+ def bot(history):
28
+ print(history)
29
+ user_message = history[-1][0]
30
+ history[-1][1] = ""
31
+ for text in chatgptbot.ask_stream(user_message):
32
+ print(text, end="")
33
+ history[-1][1] += text
34
+ yield history
35
+
36
+ # 提交用户消息和处理回答
37
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
38
+ bot, chatbot, chatbot
39
+ )
40
+ # 清除聊天记录
41
+ clear.click(lambda: None, None, chatbot, queue=False)
42
+
43
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.29.0
2
+ ModelMerge==0.2.1