ghuman7 commited on
Commit
9bc5b30
1 Parent(s): d152b59

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration
3
+
4
+ # Load RAG components
5
+ tokenizer = RagTokenizer.from_pretrained("facebook/rag-sequence-nq")
6
+ retriever = RagRetriever.from_pretrained("facebook/rag-sequence-nq", use_dummy_dataset=True)
7
+ rag_model = RagSequenceForGeneration.from_pretrained("facebook/rag-sequence-nq", retriever=retriever)
8
+
9
+ # Streamlit UI
10
+ st.title("RAG-based Q&A")
11
+
12
+ query = st.text_input("Enter your question:")
13
+
14
+ if st.button("Generate Answer"):
15
+ if query:
16
+ # Process the input query and generate a response
17
+ inputs = tokenizer(query, return_tensors="pt")
18
+ outputs = rag_model.generate(**inputs)
19
+ response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
20
+ st.write(f"Answer: {response[0]}")
21
+ else:
22
+ st.write("Please enter a question to get an answer.")