Dao3 commited on
Commit
7ccd393
·
1 Parent(s): 6ce432e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -31
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>File GPT 🤖<small> by <a href="https://codegpt.co">Code GPT</a></small></h1>', unsafe_allow_html=True)
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="Paste your OpenAI API key here (sk-...)",
36
- help="You can get your API key from 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
- "Upload a pdf, docx, or txt file",
44
  type=["pdf", "docx", "txt", "csv", "pptx", "js", "py", "json", "html", "css", "md"],
45
- help="Scanned documents are not supported yet!",
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("File type not supported")
63
  #doc = None
64
  text = text_to_docs(doc)
65
  st.write(text)
66
  try:
67
- with st.spinner("Indexing document... This may take a while⏳"):
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("### How does it work?")
76
- st.write("File GPT is a tool that allows you to ask questions about a document and get answers from the document. The tool uses the OpenAI API to embed the document and then uses the Embedding API to find the most similar documents to the question. The tool then uses LangChain to obtain the answer from the most similar documents.")
77
- st.write("The tool is currently in beta and is not perfect. It is recommended to use it with short documents.")
78
- st.write("""---""")
79
- st.markdown("### How to use it?")
80
- st.write("To use the tool you must first add your OpenAI API Key and then upload a document. The tool currently supports the following file types: pdf, docx, txt, csv, pptx. Once the document is uploaded, the tool will index the document and embed it. This may take a while depending on the size of the document. Once the document is indexed, you can ask questions about the document. The tool will return the answer to the question and the source of the answer.")
81
- st.markdown('<p>Read the article to know more details: <a target="_blank" href="https://medium.com/@dan.avila7/file-gpt-conversaci%C3%B3n-por-chat-con-un-archivo-698d17570358">Medium Article (Spanish)</a></p>', unsafe_allow_html=True)
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('To obtain an API Key you must create an OpenAI account at the following link: https://openai.com/api/')
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("Ask me something about the document:")
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("Please enter a question!")
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)