RAG / app.py
ghuman7's picture
Create app.py
9bc5b30 verified
raw
history blame
877 Bytes
import streamlit as st
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration
# Load RAG components
tokenizer = RagTokenizer.from_pretrained("facebook/rag-sequence-nq")
retriever = RagRetriever.from_pretrained("facebook/rag-sequence-nq", use_dummy_dataset=True)
rag_model = RagSequenceForGeneration.from_pretrained("facebook/rag-sequence-nq", retriever=retriever)
# Streamlit UI
st.title("RAG-based Q&A")
query = st.text_input("Enter your question:")
if st.button("Generate Answer"):
if query:
# Process the input query and generate a response
inputs = tokenizer(query, return_tensors="pt")
outputs = rag_model.generate(**inputs)
response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
st.write(f"Answer: {response[0]}")
else:
st.write("Please enter a question to get an answer.")