Spaces:
Runtime error
Runtime error
Download app.py from preethiSp/rag-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 988 Bytes
-
https://huggingface.co/spaces/preethiSp/rag-chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/preethiSp/rag-chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/preethiSp/rag-chatbot/resolve/main/app.py
988 Bytes
| 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() | |