Spaces:
Sleeping
Sleeping
dongyubin
commited on
Commit
·
3fdead9
1
Parent(s):
be69f07
更新布局
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import gradio
|
2 |
import os
|
3 |
|
4 |
from langchain.chains.question_answering import load_qa_chain
|
@@ -14,35 +14,33 @@ from langchain import OpenAI
|
|
14 |
# os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
|
15 |
# os.environ["LANGCHAIN_API_KEY"] = "ls__ae9b316f4ee9475b84f66c616344d713"
|
16 |
# os.environ["LANGCHAIN_PROJECT"] = "Sequential-Chain"
|
17 |
-
|
18 |
-
os.environ[
|
19 |
-
os.environ['OPENAI_API_BASE'] = 'https://api.chatanywhere.com.cn'
|
20 |
|
21 |
llm=OpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=1024)
|
22 |
|
23 |
def main():
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
gradio_interface.launch()
|
31 |
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
# response = chain.run(input_documents=data, question="Summarize this article in a paragraph and provide a name and link")
|
38 |
-
# Please summarize the content of the article in 50 words in Chinese.
|
39 |
-
response = chain.run(input_documents=data, question="""请用中文总结文章的内容,并以下面模版给出结果:
|
40 |
《文章标题》摘要如下:
|
41 |
## 一句话描述
|
42 |
文章摘要内容
|
43 |
## 文章略读
|
44 |
文章要点""")
|
45 |
-
|
46 |
|
47 |
if __name__ == '__main__':
|
48 |
main()
|
|
|
1 |
+
import gradio as gr
|
2 |
import os
|
3 |
|
4 |
from langchain.chains.question_answering import load_qa_chain
|
|
|
14 |
# os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
|
15 |
# os.environ["LANGCHAIN_API_KEY"] = "ls__ae9b316f4ee9475b84f66c616344d713"
|
16 |
# os.environ["LANGCHAIN_PROJECT"] = "Sequential-Chain"
|
17 |
+
# os.environ["OPENAI_API_KEY"] = 'sk-siyoMOttFuCrzfdETrRFS7bz140Dk5DUklCIW3UyVTzooiKj'
|
18 |
+
# os.environ['OPENAI_API_BASE'] = 'https://api.chatanywhere.com.cn'
|
|
|
19 |
|
20 |
llm=OpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=1024)
|
21 |
|
22 |
def main():
|
23 |
|
24 |
+
input_api_key = gr.inputs.Textbox(label="API Key", lines=1)
|
25 |
+
input_api_base = gr.inputs.Textbox(label="API Base", lines=1)
|
26 |
+
input_url = gr.inputs.Textbox(label="URL", lines=1)
|
27 |
+
gradio_interface = gr.Interface(fn=my_inference_function, inputs=[input_api_key, input_api_base, input_url], outputs="text")
|
|
|
28 |
gradio_interface.launch()
|
29 |
|
30 |
+
def my_inference_function(api_key, api_base, url):
|
31 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
32 |
+
os.environ['OPENAI_API_BASE'] = api_base
|
33 |
|
34 |
+
loader = UnstructuredURLLoader(urls=[url])
|
35 |
+
data = loader.load()
|
36 |
+
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
37 |
+
response = chain.run(input_documents=data, question="""请用中文总结文章的内容,并以下面模版给出结果:
|
|
|
|
|
|
|
38 |
《文章标题》摘要如下:
|
39 |
## 一句话描述
|
40 |
文章摘要内容
|
41 |
## 文章略读
|
42 |
文章要点""")
|
43 |
+
return response
|
44 |
|
45 |
if __name__ == '__main__':
|
46 |
main()
|