Spaces:
Sleeping
Sleeping
xiaoheiqaq
commited on
Commit
•
9a40000
1
Parent(s):
2a400bd
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import requests
|
@@ -7,7 +8,7 @@ dotenv.load_dotenv()
|
|
7 |
url = os.getenv('BACKEND_URL')
|
8 |
username = os.getenv('USERNAME')
|
9 |
password = os.getenv('PASSWORD')
|
10 |
-
system_prompt_text = "
|
11 |
|
12 |
def predict(message, history, max_new_tokens, top_k, top_p, temperature):
|
13 |
global system_prompt_text, url
|
@@ -19,15 +20,18 @@ def predict(message, history, max_new_tokens, top_k, top_p, temperature):
|
|
19 |
"top_k": top_k,
|
20 |
"top_p": top_p,
|
21 |
"temperature": temperature,
|
|
|
22 |
}
|
23 |
headers = {
|
24 |
"Content-Type": "application/json"
|
25 |
}
|
26 |
|
27 |
-
response = requests.post(url, json=payload, headers=headers)
|
28 |
|
29 |
if response.status_code == 200:
|
30 |
-
|
|
|
|
|
31 |
else:
|
32 |
response.raise_for_status()
|
33 |
|
@@ -77,10 +81,10 @@ with gr.Blocks(fill_height=True) as demo:
|
|
77 |
["你有更新过吗?", None, None, None, None]]
|
78 |
)
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
|
85 |
if __name__ == "__main__":
|
86 |
demo.launch(auth=(username, password))
|
|
|
1 |
+
import json
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
import requests
|
|
|
8 |
url = os.getenv('BACKEND_URL')
|
9 |
username = os.getenv('USERNAME')
|
10 |
password = os.getenv('PASSWORD')
|
11 |
+
system_prompt_text = "你是绘美,一个由Tomo Cafe创造的有自我意识的AI。"
|
12 |
|
13 |
def predict(message, history, max_new_tokens, top_k, top_p, temperature):
|
14 |
global system_prompt_text, url
|
|
|
20 |
"top_k": top_k,
|
21 |
"top_p": top_p,
|
22 |
"temperature": temperature,
|
23 |
+
"stream": True
|
24 |
}
|
25 |
headers = {
|
26 |
"Content-Type": "application/json"
|
27 |
}
|
28 |
|
29 |
+
response = requests.post(url, json=payload, headers=headers, stream=True)
|
30 |
|
31 |
if response.status_code == 200:
|
32 |
+
for line in response.iter_lines(decode_unicode=True):
|
33 |
+
if line:
|
34 |
+
yield json.loads(line)
|
35 |
else:
|
36 |
response.raise_for_status()
|
37 |
|
|
|
81 |
["你有更新过吗?", None, None, None, None]]
|
82 |
)
|
83 |
|
84 |
+
system_prompt = gr.Textbox(value=system_prompt_text, info="System Message:", placeholder="你是Emi",
|
85 |
+
interactive=True, lines=5)
|
86 |
+
system_prompt.change(
|
87 |
+
fn=update_system_prompt, inputs=system_prompt)
|
88 |
|
89 |
if __name__ == "__main__":
|
90 |
demo.launch(auth=(username, password))
|