Spaces:
Runtime error
Runtime error
正经人王同学 commited on
Commit ·
fe30923
1
Parent(s): 72cff29
app.py
CHANGED
|
@@ -2,8 +2,30 @@ import streamlit as st
|
|
| 2 |
from streamlit_chat import message
|
| 3 |
import os
|
| 4 |
import openai
|
| 5 |
-
|
| 6 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# openAI code
|
| 8 |
def openai_create(prompt):
|
| 9 |
try:
|
|
@@ -20,20 +42,29 @@ def openai_create(prompt):
|
|
| 20 |
)
|
| 21 |
|
| 22 |
return response.choices[0].text
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
def chatgpt_clone(input):
|
| 29 |
output = openai_create(input)
|
| 30 |
return output
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
st.set_page_config(
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
)
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
# st.header("🏅和小译学长聊聊天")
|
| 39 |
|
|
@@ -45,8 +76,8 @@ if 'past' not in st.session_state:
|
|
| 45 |
|
| 46 |
|
| 47 |
def get_text():
|
| 48 |
-
input_text = st.text_input("📫请告诉小译学长你想说的吧: ", key="
|
| 49 |
-
if st.button("发送"):
|
| 50 |
return input_text
|
| 51 |
return None
|
| 52 |
|
|
|
|
| 2 |
from streamlit_chat import message
|
| 3 |
import os
|
| 4 |
import openai
|
| 5 |
+
|
| 6 |
+
#页面设置
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
page_title="小译AI对话单轮版",
|
| 9 |
+
page_icon=":robot:"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
#检查账号登陆
|
| 13 |
+
def get_text1():
|
| 14 |
+
if 'openai_key' not in st.session_state:
|
| 15 |
+
input_text1 = st.text_input("📫请请输入你的账号: ", key="input")
|
| 16 |
+
if st.button("发送", key="input3"):
|
| 17 |
+
st.session_state['openai_key'] = input_text1
|
| 18 |
+
return input_text1
|
| 19 |
+
else:
|
| 20 |
+
return st.session_state['openai_key']
|
| 21 |
+
|
| 22 |
+
openai_key = get_text1()
|
| 23 |
+
if openai_key:
|
| 24 |
+
openai.api_key = openai_key
|
| 25 |
+
st.write("")
|
| 26 |
+
else:
|
| 27 |
+
st.write("请输入 OpenAI API Key")
|
| 28 |
+
|
| 29 |
# openAI code
|
| 30 |
def openai_create(prompt):
|
| 31 |
try:
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
return response.choices[0].text
|
| 45 |
+
|
| 46 |
+
# except openai.error.UnauthorizedError:
|
| 47 |
+
# return "API Key不正确,请输入正确的API Key。"
|
| 48 |
+
# except openai.error.RateLimitError:
|
| 49 |
+
# Error="当前小译学长访问量过大,请过一段时间再试!开发者正在努力扩张服务能力,敬请期待!"
|
| 50 |
+
# return Error
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
return "你的账号填写有误,请刷新页面重新填写正确的账号!"
|
| 54 |
|
| 55 |
|
| 56 |
def chatgpt_clone(input):
|
| 57 |
output = openai_create(input)
|
| 58 |
return output
|
| 59 |
|
| 60 |
+
# Streamlit App
|
| 61 |
+
# st.set_page_config(
|
| 62 |
+
# page_title="小译AI对话单轮版",
|
| 63 |
+
# page_icon=":robot:"
|
| 64 |
+
# )
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
|
| 69 |
# st.header("🏅和小译学长聊聊天")
|
| 70 |
|
|
|
|
| 76 |
|
| 77 |
|
| 78 |
def get_text():
|
| 79 |
+
input_text = st.text_input("📫请告诉小译学长你想说的吧: ", key="input1")
|
| 80 |
+
if st.button("发送", key="input2"):
|
| 81 |
return input_text
|
| 82 |
return None
|
| 83 |
|