Spaces:
Runtime error
Runtime error
dongyubin
commited on
Commit
·
4f05ca4
1
Parent(s):
5bf9849
更新
Browse files
app.py
CHANGED
|
@@ -17,26 +17,35 @@ 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 |
-
gradio_interface = gr.Interface(fn=my_inference_function, inputs=[input_checkbox, input_api_key, input_api_base, input_url], outputs="text")
|
| 21 |
-
gradio_interface.launch()
|
| 22 |
|
| 23 |
-
def my_inference_function(enabled, api_key, api_base, url):
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
《文章标题》摘要如下:
|
| 35 |
## 一句话描述
|
| 36 |
文章摘要内容
|
| 37 |
## 文章略读
|
| 38 |
文章要点""")
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
if __name__ == '__main__':
|
| 42 |
-
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 |
|
| 21 |
+
def my_inference_function(enabled, api_key, api_base, url):
|
| 22 |
+
if enabled:
|
| 23 |
+
os.environ["OPENAI_API_KEY"] = api_key
|
| 24 |
+
os.environ['OPENAI_API_BASE'] = api_base
|
| 25 |
+
llm = OpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=1024)
|
| 26 |
+
else:
|
| 27 |
+
llm = HuggingFaceHub(repo_id="declare-lab/flan-alpaca-large", model_kwargs={"temperature":0.1, "max_length":512})
|
| 28 |
+
loader = UnstructuredURLLoader(urls=[url])
|
| 29 |
+
data = loader.load()
|
| 30 |
+
chain = load_qa_chain(llm=llm, chain_type="stuff")
|
| 31 |
+
response = chain.run(input_documents=data, question="""请用中文总结文章的内容,并以下面模版给出结果:
|
| 32 |
《文章标题》摘要如下:
|
| 33 |
## 一句话描述
|
| 34 |
文章摘要内容
|
| 35 |
## 文章略读
|
| 36 |
文章要点""")
|
| 37 |
+
return response
|
| 38 |
+
|
| 39 |
+
inputs = [input_checkbox]
|
| 40 |
+
outputs = "text"
|
| 41 |
+
if input_checkbox.default is False:
|
| 42 |
+
inputs += [input_url]
|
| 43 |
+
else:
|
| 44 |
+
inputs += [input_api_key, input_api_base]
|
| 45 |
+
|
| 46 |
+
gradio_interface = gr.Interface(fn=my_inference_function, inputs=inputs, outputs=outputs)
|
| 47 |
+
gradio_interface.launch()
|
| 48 |
+
|
| 49 |
|
| 50 |
if __name__ == '__main__':
|
| 51 |
+
main()
|