Spaces:
Runtime error
Runtime error
marcelo-castro-cardoso
commited on
Commit
•
a7ab009
1
Parent(s):
4bbe624
correcao de dependencia
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from transformers import pipeline
|
|
6 |
from langchain.llms.base import LLM
|
7 |
from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, PromptHelper, LLMPredictor, ServiceContext
|
8 |
from llama_index.langchain_helpers.text_splitter import TokenTextSplitter
|
9 |
-
from llama_index.node_parser import
|
10 |
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
11 |
|
12 |
from llama_index.embeddings import LangchainEmbedding
|
@@ -17,8 +17,9 @@ index_files = list(Path(INPUT_FOLDER).glob("*"))
|
|
17 |
|
18 |
max_input_size = 2048
|
19 |
num_output = 256
|
20 |
-
max_chunk_overlap =
|
21 |
-
|
|
|
22 |
|
23 |
pipe = pipeline("text-generation", model="databricks/dolly-v2-3b", trust_remote_code=True, torch_dtype=torch.bfloat16, device_map="auto")
|
24 |
embed_model = LangchainEmbedding(HuggingFaceEmbeddings())
|
@@ -41,8 +42,8 @@ class CustomLLM(LLM):
|
|
41 |
# define our LLM
|
42 |
llm_predictor = LLMPredictor(llm=CustomLLM())
|
43 |
|
44 |
-
node_parser =
|
45 |
-
prompt_helper = PromptHelper(max_input_size, num_output,
|
46 |
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embed_model, prompt_helper=prompt_helper, node_parser=node_parser, chunk_size_limit=512)
|
47 |
# Load your data
|
48 |
documents = SimpleDirectoryReader(input_files=index_files).load_data()
|
@@ -55,4 +56,4 @@ def greet(query):
|
|
55 |
return query_engine.query(query)
|
56 |
|
57 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
58 |
-
iface.launch()
|
|
|
6 |
from langchain.llms.base import LLM
|
7 |
from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, PromptHelper, LLMPredictor, ServiceContext
|
8 |
from llama_index.langchain_helpers.text_splitter import TokenTextSplitter
|
9 |
+
from llama_index.node_parser import SentenceSplitter
|
10 |
from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
11 |
|
12 |
from llama_index.embeddings import LangchainEmbedding
|
|
|
17 |
|
18 |
max_input_size = 2048
|
19 |
num_output = 256
|
20 |
+
max_chunk_overlap = 20
|
21 |
+
max_prompt_chunk_overlap = 0.5
|
22 |
+
prompt_helper = PromptHelper(max_input_size, num_output, max_prompt_chunk_overlap)
|
23 |
|
24 |
pipe = pipeline("text-generation", model="databricks/dolly-v2-3b", trust_remote_code=True, torch_dtype=torch.bfloat16, device_map="auto")
|
25 |
embed_model = LangchainEmbedding(HuggingFaceEmbeddings())
|
|
|
42 |
# define our LLM
|
43 |
llm_predictor = LLMPredictor(llm=CustomLLM())
|
44 |
|
45 |
+
node_parser = SentenceSplitter(chunk_size=512, chunk_overlap=max_chunk_overlap)
|
46 |
+
prompt_helper = PromptHelper(max_input_size, num_output, max_prompt_chunk_overlap)
|
47 |
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, embed_model=embed_model, prompt_helper=prompt_helper, node_parser=node_parser, chunk_size_limit=512)
|
48 |
# Load your data
|
49 |
documents = SimpleDirectoryReader(input_files=index_files).load_data()
|
|
|
56 |
return query_engine.query(query)
|
57 |
|
58 |
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
59 |
+
iface.launch(share=True)
|