Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,7 @@ def clear_submit():
|
|
23 |
def set_openai_api_key(api_key: str):
|
24 |
st.session_state["OPENAI_API_KEY"] = api_key
|
25 |
|
26 |
-
st.markdown('<h1
|
27 |
|
28 |
# Sidebar
|
29 |
index = None
|
@@ -32,17 +32,17 @@ with st.sidebar:
|
|
32 |
user_secret = st.text_input(
|
33 |
"OpenAI API Key",
|
34 |
type="password",
|
35 |
-
placeholder="
|
36 |
-
help="
|
37 |
value=st.session_state.get("OPENAI_API_KEY", ""),
|
38 |
)
|
39 |
if user_secret:
|
40 |
set_openai_api_key(user_secret)
|
41 |
|
42 |
uploaded_file = st.file_uploader(
|
43 |
-
"
|
44 |
type=["pdf", "docx", "txt", "csv", "pptx", "js", "py", "json", "html", "css", "md"],
|
45 |
-
help="
|
46 |
on_change=clear_submit,
|
47 |
)
|
48 |
|
@@ -59,12 +59,12 @@ with st.sidebar:
|
|
59 |
doc = parse_pptx(uploaded_file)
|
60 |
else:
|
61 |
doc = parse_any(uploaded_file)
|
62 |
-
#st.error("
|
63 |
#doc = None
|
64 |
text = text_to_docs(doc)
|
65 |
st.write(text)
|
66 |
try:
|
67 |
-
with st.spinner("
|
68 |
index = embed_docs(text)
|
69 |
st.session_state["api_key_configured"] = True
|
70 |
except OpenAIError as e:
|
@@ -72,30 +72,16 @@ with st.sidebar:
|
|
72 |
|
73 |
tab1, tab2 = st.tabs(["Intro", "Chat with the File"])
|
74 |
with tab1:
|
75 |
-
st.markdown("###
|
76 |
-
st.write("
|
77 |
-
st.write(
|
78 |
-
st.write(
|
79 |
-
|
80 |
-
|
81 |
-
st.
|
82 |
-
st.write("## File GPT was written with the following tools:")
|
83 |
-
st.markdown("#### Code GPT")
|
84 |
-
st.write('All code was written with the help of Code GPT. Visit https://codegpt.co to get the extension.')
|
85 |
-
st.markdown("#### Streamlit")
|
86 |
-
st.write('The design was written with <a target="_blank" href="https://streamlit.io/">Streamlit</a>.', unsafe_allow_html=True)
|
87 |
-
st.markdown("#### LangChain")
|
88 |
-
st.write('Question answering with source <a target="_blank" href="https://langchain.readthedocs.io/en/latest/use_cases/question_answering.html#adding-in-sources">Langchain QA</a>.', unsafe_allow_html=True)
|
89 |
-
st.markdown("#### Embedding")
|
90 |
-
st.write('<a target="_blank" href="https://platform.openai.com/docs/guides/embeddings">Embedding</a> is done via the OpenAI API with "text-embedding-ada-002"', unsafe_allow_html=True)
|
91 |
-
st.write("Please note that you must have credits in your OpenAI account to use this tool. Each file uploaded to the platform consumes credits for embedding and each query consumes credits to obtain the response.")
|
92 |
-
st.markdown("""---""")
|
93 |
-
st.write('Author: <a target="_blank" href="https://www.linkedin.com/in/daniel-avila-arias/">Daniel Avila</a>', unsafe_allow_html=True)
|
94 |
-
st.write('Repo: <a target="_blank" href="https://github.com/davila7/file-gpt">Github</a>', unsafe_allow_html=True)
|
95 |
-
st.write("This software was developed with Code GPT, for more information visit: https://codegpt.co", unsafe_allow_html=True)
|
96 |
|
97 |
with tab2:
|
98 |
-
st.write('
|
99 |
if 'generated' not in st.session_state:
|
100 |
st.session_state['generated'] = []
|
101 |
|
@@ -104,7 +90,7 @@ with tab2:
|
|
104 |
|
105 |
def get_text():
|
106 |
if user_secret:
|
107 |
-
st.header("
|
108 |
input_text = st.text_area("You:", on_change=clear_submit)
|
109 |
return input_text
|
110 |
user_input = get_text()
|
@@ -112,7 +98,7 @@ with tab2:
|
|
112 |
button = st.button("Submit")
|
113 |
if button or st.session_state.get("submit"):
|
114 |
if not user_input:
|
115 |
-
st.error("
|
116 |
else:
|
117 |
st.session_state["submit"] = True
|
118 |
sources = search_docs(index, user_input)
|
|
|
23 |
def set_openai_api_key(api_key: str):
|
24 |
st.session_state["OPENAI_API_KEY"] = api_key
|
25 |
|
26 |
+
st.markdown('<h1>和文档聊聊💬 <small> by <a href="https://i-robotlife">I-Robot.Life</a></small></h1>', unsafe_allow_html=True)
|
27 |
|
28 |
# Sidebar
|
29 |
index = None
|
|
|
32 |
user_secret = st.text_input(
|
33 |
"OpenAI API Key",
|
34 |
type="password",
|
35 |
+
placeholder="输入你的api-key (sk-开头)",
|
36 |
+
help="api-key应该从官网获取 https://platform.openai.com/account/api-keys.",
|
37 |
value=st.session_state.get("OPENAI_API_KEY", ""),
|
38 |
)
|
39 |
if user_secret:
|
40 |
set_openai_api_key(user_secret)
|
41 |
|
42 |
uploaded_file = st.file_uploader(
|
43 |
+
"上传你的文档,可以是pdf, docx, txt,扫描、影印的pdf暂不支持",
|
44 |
type=["pdf", "docx", "txt", "csv", "pptx", "js", "py", "json", "html", "css", "md"],
|
45 |
+
help="扫描、影印的pdf暂不支持!",
|
46 |
on_change=clear_submit,
|
47 |
)
|
48 |
|
|
|
59 |
doc = parse_pptx(uploaded_file)
|
60 |
else:
|
61 |
doc = parse_any(uploaded_file)
|
62 |
+
#st.error("文档格式不支持")
|
63 |
#doc = None
|
64 |
text = text_to_docs(doc)
|
65 |
st.write(text)
|
66 |
try:
|
67 |
+
with st.spinner("正在拼命阅读... 你可以去接杯水再回来看看⏳"):
|
68 |
index = embed_docs(text)
|
69 |
st.session_state["api_key_configured"] = True
|
70 |
except OpenAIError as e:
|
|
|
72 |
|
73 |
tab1, tab2 = st.tabs(["Intro", "Chat with the File"])
|
74 |
with tab1:
|
75 |
+
st.markdown("### 使用指南")
|
76 |
+
st.write("1,输入可用的api-key.")
|
77 |
+
st.write('2,上传文档...等待解析完成')
|
78 |
+
st.write('3,提问,得到回答')
|
79 |
+
|
80 |
+
|
81 |
+
st.write('感谢<a target="_blank" href="https://www.linkedin.com/in/daniel-avila-arias/">Daniel Avila</a>,感谢<a target="_blank" href="https://www.github.com.com/">Github</a>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
with tab2:
|
84 |
+
st.write('从官网链接获取apikey link: https://openai.com/api/')
|
85 |
if 'generated' not in st.session_state:
|
86 |
st.session_state['generated'] = []
|
87 |
|
|
|
90 |
|
91 |
def get_text():
|
92 |
if user_secret:
|
93 |
+
st.header("关于文档,你想问..?")
|
94 |
input_text = st.text_area("You:", on_change=clear_submit)
|
95 |
return input_text
|
96 |
user_input = get_text()
|
|
|
98 |
button = st.button("Submit")
|
99 |
if button or st.session_state.get("submit"):
|
100 |
if not user_input:
|
101 |
+
st.error("请输入问题")
|
102 |
else:
|
103 |
st.session_state["submit"] = True
|
104 |
sources = search_docs(index, user_input)
|