|
import streamlit as st |
|
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration |
|
|
|
|
|
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) |
|
|
|
|
|
st.title("RAG-based Q&A") |
|
|
|
query = st.text_input("Enter your question:") |
|
|
|
if st.button("Generate Answer"): |
|
if query: |
|
|
|
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.") |
|
|