chappyzhou commited on
Commit
1ef08ce
·
1 Parent(s): 495a9d1
Files changed (1) hide show
  1. app.py +38 -2
app.py CHANGED
@@ -1,4 +1,40 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import time
3
+ import requests
4
 
5
+ st.header("DeeplySorry")
6
+
7
+ all_input = st.text_area('模型输入', value="""
8
+ 今天,我们正式发布名为 DeeplySorry 的大规模神经网络模型,它可以代替您向您珍惜的亲人、朋友、爱人道歉。\n""", height=100)
9
+
10
+ max_tokens = st.slider('生成的最大长度', min_value=15, max_value=1024, value=64)
11
+
12
+
13
+ def completion(prompt):
14
+ start = time.monotonic()
15
+ resp = requests.post('https://welm.weixin.qq.com/v1/completions', json={
16
+ 'prompt': prompt,
17
+ 'max_tokens': max_tokens,
18
+ 'temperature': 0.85,
19
+ 'top_p': 0.95,
20
+ 'top_k': 0.0,
21
+ 'n': 5,
22
+ 'stop': None,
23
+ # 'stop': [[13, 13]],
24
+ }, headers={"Authorization": f"Bearer {st.secrets['token']}"})
25
+ answers = resp.json()
26
+ print(answers)
27
+ answers = [c['text'] for c in answers['choices'] if c['text'] is not None]
28
+ cols = st.columns(3)
29
+ for idx, answer in enumerate(answers):
30
+ if idx >= 3:
31
+ break
32
+ with cols[idx]:
33
+ content = (prompt + answer).replace("\n", "\n\n")
34
+ st.markdown(f'## 版本{idx}\n\n{content}')
35
+ end = time.monotonic()
36
+ st.text(f'耗时:{end - start}')
37
+
38
+
39
+ if st.button('开始生成/换一批'):
40
+ completion(all_input)