Spaces:
Sleeping
Sleeping
DongYubin
commited on
Commit
·
51c2df6
1
Parent(s):
f979ae8
更新样式
Browse files
app.py
CHANGED
@@ -5,7 +5,8 @@ from langchain.chains.question_answering import load_qa_chain
|
|
5 |
from langchain.document_loaders import UnstructuredURLLoader
|
6 |
from langchain import OpenAI
|
7 |
from langchain import HuggingFaceHub
|
8 |
-
os.environ[
|
|
|
9 |
os.environ["LANGCHAIN_TRACING_V2"] = "true"
|
10 |
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
|
11 |
os.environ["LANGCHAIN_API_KEY"] = "ls__ae9b316f4ee9475b84f66c616344d713"
|
@@ -13,42 +14,53 @@ os.environ["LANGCHAIN_PROJECT"] = "Sequential-Chain"
|
|
13 |
|
14 |
|
15 |
def main():
|
16 |
-
|
|
|
|
|
17 |
outputs = "text"
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
interface.launch()
|
20 |
|
21 |
-
def check_model(enabled):
|
22 |
-
input_api_key = gr.inputs.Textbox(label="ChatGPT API Key", lines=1)
|
23 |
-
input_api_base = gr.inputs.Textbox(label="ChatGPT API 地址(默认无地址)", lines=1)
|
24 |
-
input_url = gr.inputs.Textbox(label="URL", lines=1)
|
25 |
-
if enabled:
|
26 |
-
return [input_url,input_api_key, input_api_base]
|
27 |
-
else:
|
28 |
-
return [input_url]
|
29 |
|
30 |
def my_chatgpt_function(api_key, api_base, url):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
38 |
《文章标题》摘要如下:
|
39 |
## 一句话描述
|
40 |
文章摘要内容
|
41 |
## 文章略读
|
42 |
文章要点""")
|
43 |
-
|
|
|
44 |
|
45 |
def my_inference_function(url):
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
if __name__ == '__main__':
|
54 |
main()
|
|
|
5 |
from langchain.document_loaders import UnstructuredURLLoader
|
6 |
from langchain import OpenAI
|
7 |
from langchain import HuggingFaceHub
|
8 |
+
os.environ[
|
9 |
+
"HUGGINGFACEHUB_API_TOKEN"] = "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"
|
10 |
os.environ["LANGCHAIN_TRACING_V2"] = "true"
|
11 |
os.environ["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"
|
12 |
os.environ["LANGCHAIN_API_KEY"] = "ls__ae9b316f4ee9475b84f66c616344d713"
|
|
|
14 |
|
15 |
|
16 |
def main():
|
17 |
+
input_api_key = gr.inputs.Textbox(label="ChatGPT API Key", lines=1)
|
18 |
+
input_api_base = gr.inputs.Textbox(label="ChatGPT API 地址(默认无地址)", lines=1)
|
19 |
+
input_url = gr.inputs.Textbox(label="URL", lines=1)
|
20 |
outputs = "text"
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
with gr.Tab("Component 1"): #标签页1
|
23 |
+
interface = gr.Interface(fn=my_inference_function,
|
24 |
+
inputs=[input_url],
|
25 |
+
outputs=outputs)
|
26 |
+
with gr.Tab("Component 2"): #标签页2
|
27 |
+
interface = gr.Interface(
|
28 |
+
fn=my_chatgpt_function,
|
29 |
+
inputs=[input_api_key, input_api_base, input_url],
|
30 |
+
outputs=outputs)
|
31 |
interface.launch()
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def my_chatgpt_function(api_key, api_base, url):
|
35 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
36 |
+
os.environ['OPENAI_API_BASE'] = api_base
|
37 |
+
llm = OpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=1024)
|
38 |
+
loader = UnstructuredURLLoader(urls=[url])
|
39 |
+
data = loader.load()
|
40 |
+
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
41 |
+
response = chain.run(input_documents=data,
|
42 |
+
question="""请用中文总结文章的内容,并以下面模版给出结果:
|
43 |
《文章标题》摘要如下:
|
44 |
## 一句话描述
|
45 |
文章摘要内容
|
46 |
## 文章略读
|
47 |
文章要点""")
|
48 |
+
return response
|
49 |
+
|
50 |
|
51 |
def my_inference_function(url):
|
52 |
+
llm = HuggingFaceHub(repo_id="declare-lab/flan-alpaca-large",
|
53 |
+
model_kwargs={
|
54 |
+
"temperature": 0.1,
|
55 |
+
"max_length": 512
|
56 |
+
})
|
57 |
+
loader = UnstructuredURLLoader(urls=[url])
|
58 |
+
data = loader.load()
|
59 |
+
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
60 |
+
response = chain.run(input_documents=data,
|
61 |
+
question="Summarize this article in one paragraph")
|
62 |
+
return response
|
63 |
+
|
64 |
|
65 |
if __name__ == '__main__':
|
66 |
main()
|