Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,38 +52,30 @@ def process_urls_with_logs(url1, url2, url3):
|
|
| 52 |
urls = [u for u in urls if u.strip() != ""]
|
| 53 |
|
| 54 |
if len(urls) == 0:
|
| 55 |
-
yield "⚠️ Please provide at least one URL."
|
| 56 |
return
|
| 57 |
|
| 58 |
-
yield "⏳ Loading URLs..."
|
| 59 |
loader = UnstructuredURLLoader(urls=urls)
|
| 60 |
documents = loader.load()
|
| 61 |
|
| 62 |
-
yield "⏳ Creating the chunks..."
|
| 63 |
-
text_splitter = RecursiveCharacterTextSplitter(
|
| 64 |
-
chunk_size=600,
|
| 65 |
-
chunk_overlap=200
|
| 66 |
-
)
|
| 67 |
splits = text_splitter.split_documents(documents)
|
| 68 |
|
| 69 |
-
yield "⏳ Creating embeddings..."
|
| 70 |
-
embeddings = HuggingFaceEmbeddings(
|
| 71 |
-
model_name="mixedbread-ai/mxbai-embed-large-v1"
|
| 72 |
-
)
|
| 73 |
|
| 74 |
-
yield "⏳ Creating a vector database-like structure (FAISS)..."
|
| 75 |
-
vectorstore = FAISS.from_documents(
|
| 76 |
-
documents=splits,
|
| 77 |
-
embedding=embeddings
|
| 78 |
-
)
|
| 79 |
|
| 80 |
-
yield "⏳ Starting LLM model (meta-llama/Llama-2-7b-hf)..."
|
| 81 |
retriever = vectorstore.as_retriever()
|
| 82 |
|
| 83 |
from langchain_core.runnables import RunnableSequence
|
| 84 |
simple_chain = RunnableSequence(prompt, llm, StrOutputParser())
|
| 85 |
|
| 86 |
-
yield "✅ URLs processed successfully!"
|
| 87 |
|
| 88 |
# ------------------------
|
| 89 |
# Function to answer questions
|
|
@@ -126,12 +118,11 @@ with gr.Blocks() as app:
|
|
| 126 |
ask_btn = gr.Button("Ask")
|
| 127 |
answer_output = gr.Textbox(label="Answer", lines=8)
|
| 128 |
|
| 129 |
-
# Connect buttons to
|
| 130 |
process_btn.click(
|
| 131 |
process_urls_with_logs,
|
| 132 |
inputs=[url1, url2, url3],
|
| 133 |
-
outputs=status_output
|
| 134 |
-
streaming=True # ⚡️ atualiza logs em tempo real
|
| 135 |
)
|
| 136 |
|
| 137 |
ask_btn.click(
|
|
|
|
| 52 |
urls = [u for u in urls if u.strip() != ""]
|
| 53 |
|
| 54 |
if len(urls) == 0:
|
| 55 |
+
yield gr.Textbox.update(value="⚠️ Please provide at least one URL.")
|
| 56 |
return
|
| 57 |
|
| 58 |
+
yield gr.Textbox.update(value="⏳ Loading URLs...")
|
| 59 |
loader = UnstructuredURLLoader(urls=urls)
|
| 60 |
documents = loader.load()
|
| 61 |
|
| 62 |
+
yield gr.Textbox.update(value="⏳ Creating the chunks...")
|
| 63 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=600, chunk_overlap=200)
|
|
|
|
|
|
|
|
|
|
| 64 |
splits = text_splitter.split_documents(documents)
|
| 65 |
|
| 66 |
+
yield gr.Textbox.update(value="⏳ Creating embeddings...")
|
| 67 |
+
embeddings = HuggingFaceEmbeddings(model_name="mixedbread-ai/mxbai-embed-large-v1")
|
|
|
|
|
|
|
| 68 |
|
| 69 |
+
yield gr.Textbox.update(value="⏳ Creating a vector database-like structure (FAISS)...")
|
| 70 |
+
vectorstore = FAISS.from_documents(documents=splits, embedding=embeddings)
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
yield gr.Textbox.update(value="⏳ Starting LLM model (meta-llama/Llama-2-7b-hf)...")
|
| 73 |
retriever = vectorstore.as_retriever()
|
| 74 |
|
| 75 |
from langchain_core.runnables import RunnableSequence
|
| 76 |
simple_chain = RunnableSequence(prompt, llm, StrOutputParser())
|
| 77 |
|
| 78 |
+
yield gr.Textbox.update(value="✅ URLs processed successfully!")
|
| 79 |
|
| 80 |
# ------------------------
|
| 81 |
# Function to answer questions
|
|
|
|
| 118 |
ask_btn = gr.Button("Ask")
|
| 119 |
answer_output = gr.Textbox(label="Answer", lines=8)
|
| 120 |
|
| 121 |
+
# Connect buttons to suas funções
|
| 122 |
process_btn.click(
|
| 123 |
process_urls_with_logs,
|
| 124 |
inputs=[url1, url2, url3],
|
| 125 |
+
outputs=status_output
|
|
|
|
| 126 |
)
|
| 127 |
|
| 128 |
ask_btn.click(
|