Spaces:
Sleeping
Sleeping
guangliang.yin
commited on
Commit
·
b4c9a1a
1
Parent(s):
efdfa77
信息读取改为文件
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ from typing import Callable, Optional
|
|
| 3 |
import gradio as gr
|
| 4 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
| 5 |
from langchain.vectorstores import Zilliz
|
| 6 |
-
from langchain.document_loaders import
|
| 7 |
from langchain.text_splitter import CharacterTextSplitter
|
| 8 |
from langchain.chains import RetrievalQAWithSourcesChain
|
| 9 |
import uuid
|
|
@@ -12,10 +12,10 @@ from project.llm.zhipuai_llm import ZhipuAILLM
|
|
| 12 |
chain: Optional[Callable] = None
|
| 13 |
|
| 14 |
|
| 15 |
-
def web_loader(
|
| 16 |
-
if not
|
| 17 |
-
return "please
|
| 18 |
-
loader =
|
| 19 |
docs = loader.load()
|
| 20 |
|
| 21 |
text_splitter = CharacterTextSplitter(chunk_size=1024, chunk_overlap=0)
|
|
@@ -88,11 +88,13 @@ if __name__ == "__main__":
|
|
| 88 |
6. 🔍 Click the Generate button to search for the answer to the question. The final answer will be displayed in the question answer text box.
|
| 89 |
"""
|
| 90 |
)
|
| 91 |
-
url_list_text = gr.Textbox(
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
)
|
|
|
|
|
|
|
| 96 |
openai_key_text = gr.Textbox(label="openai api key", type="password", placeholder="sk-******")
|
| 97 |
puzhiai_key_text = gr.Textbox(label="puzhi api key", type="password", placeholder="******")
|
| 98 |
with gr.Row():
|
|
@@ -109,7 +111,7 @@ if __name__ == "__main__":
|
|
| 109 |
loader_btn.click(
|
| 110 |
fn=web_loader,
|
| 111 |
inputs=[
|
| 112 |
-
|
| 113 |
openai_key_text,
|
| 114 |
puzhiai_key_text,
|
| 115 |
zilliz_uri_text,
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
| 5 |
from langchain.vectorstores import Zilliz
|
| 6 |
+
from langchain.document_loaders import TextLoader
|
| 7 |
from langchain.text_splitter import CharacterTextSplitter
|
| 8 |
from langchain.chains import RetrievalQAWithSourcesChain
|
| 9 |
import uuid
|
|
|
|
| 12 |
chain: Optional[Callable] = None
|
| 13 |
|
| 14 |
|
| 15 |
+
def web_loader(file, openai_key, puzhiai_key, zilliz_uri, user, password):
|
| 16 |
+
if not file:
|
| 17 |
+
return "please upload file"
|
| 18 |
+
loader = TextLoader(file)
|
| 19 |
docs = loader.load()
|
| 20 |
|
| 21 |
text_splitter = CharacterTextSplitter(chunk_size=1024, chunk_overlap=0)
|
|
|
|
| 88 |
6. 🔍 Click the Generate button to search for the answer to the question. The final answer will be displayed in the question answer text box.
|
| 89 |
"""
|
| 90 |
)
|
| 91 |
+
# url_list_text = gr.Textbox(
|
| 92 |
+
# label="url list",
|
| 93 |
+
# lines=3,
|
| 94 |
+
# placeholder="https://milvus.io/docs/overview.md",
|
| 95 |
+
# )
|
| 96 |
+
file = gr.File(label='请上传知识库文件',
|
| 97 |
+
file_types=['.txt', '.md', '.docx', '.pdf'])
|
| 98 |
openai_key_text = gr.Textbox(label="openai api key", type="password", placeholder="sk-******")
|
| 99 |
puzhiai_key_text = gr.Textbox(label="puzhi api key", type="password", placeholder="******")
|
| 100 |
with gr.Row():
|
|
|
|
| 111 |
loader_btn.click(
|
| 112 |
fn=web_loader,
|
| 113 |
inputs=[
|
| 114 |
+
file,
|
| 115 |
openai_key_text,
|
| 116 |
puzhiai_key_text,
|
| 117 |
zilliz_uri_text,
|