File size: 877 Bytes
9bc5b30 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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.")
|