Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from langchain_community.vectorstores import FAISS
|
|
| 6 |
#from langchain_community.vectorstores import Chroma
|
| 7 |
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
| 8 |
#from langchain_community.embeddings import OllamaEmbeddings
|
| 9 |
-
import ollama
|
| 10 |
|
| 11 |
# Function to load, split, and retrieve documents from a URL
|
| 12 |
def load_and_retrieve_docs(url):
|
|
@@ -48,8 +47,12 @@ def rag_chain(url, question):
|
|
| 48 |
retrieved_docs = retriever.invoke(question)
|
| 49 |
formatted_context = format_docs(retrieved_docs)
|
| 50 |
formatted_prompt = f"Question: {question}\n\nContext: {formatted_context}"
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# Gradio interface
|
| 55 |
iface = gr.Interface(
|
|
|
|
| 6 |
#from langchain_community.vectorstores import Chroma
|
| 7 |
from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
| 8 |
#from langchain_community.embeddings import OllamaEmbeddings
|
|
|
|
| 9 |
|
| 10 |
# Function to load, split, and retrieve documents from a URL
|
| 11 |
def load_and_retrieve_docs(url):
|
|
|
|
| 47 |
retrieved_docs = retriever.invoke(question)
|
| 48 |
formatted_context = format_docs(retrieved_docs)
|
| 49 |
formatted_prompt = f"Question: {question}\n\nContext: {formatted_context}"
|
| 50 |
+
|
| 51 |
+
# Using HuggingFace transformers for generating response
|
| 52 |
+
chat_pipeline = pipeline('text-generation', model='Llama3-8b-8192') # Use the appropriate model here
|
| 53 |
+
response = chat_pipeline(formatted_prompt, max_length=512, num_return_sequences=1)
|
| 54 |
+
|
| 55 |
+
return response[0]['generated_text']
|
| 56 |
|
| 57 |
# Gradio interface
|
| 58 |
iface = gr.Interface(
|