Spaces:
Runtime error
Runtime error
File size: 988 Bytes
b5a13e5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import gradio as gr
from langchain.text_splitter import CharacterTextSplitter
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import FAISS
from langchain.llms import HuggingFaceHub
from langchain.chains import RetrievalQA
# Sample knowledge
texts = [
"RAG stands for Retrieval Augmented Generation.",
"Hugging Face provides models, datasets, and spaces for ML projects.",
"RAG combines document search with language models."
]
# Split text
splitter = CharacterTextSplitter(chunk_size=100, chunk_overlap=20)
docs = splitter.create_documents(texts)
# Embeddings
embeddings = HuggingFaceEmbeddings()
# Vector database
db = FAISS.from_documents(docs, embeddings)
# LLM
llm = HuggingFaceHub(repo_id="google/flan-t5-large")
qa = RetrievalQA.from_chain_type(llm=llm, retriever=db.as_retriever())
def chat(question):
return qa.run(question)
demo = gr.Interface(fn=chat, inputs="text", outputs="text", title="RAG Chatbot")
demo.launch()
|