Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
%%writefile app.py
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
4 |
+
|
5 |
+
# Load the model and tokenizer
|
6 |
+
model = T5ForConditionalGeneration.from_pretrained('/content/fine_tuned_model')
|
7 |
+
tokenizer = T5Tokenizer.from_pretrained('/content/fine_tuned_model')
|
8 |
+
|
9 |
+
def generate_answer(question, distractors):
|
10 |
+
input_text = f"Question: {question} Distractors: {' '.join(distractors)}"
|
11 |
+
inputs = tokenizer(input_text, return_tensors='pt')
|
12 |
+
output = model.generate(inputs['input_ids'], attention_mask=inputs['attention_mask'])
|
13 |
+
decoded_output = tokenizer.decode(output[0], skip_special_tokens=True)
|
14 |
+
return decoded_output
|
15 |
+
|
16 |
+
st.title('Question Answering Model')
|
17 |
+
question = st.text_input('Enter your question:')
|
18 |
+
distractors = st.text_input('Enter distractors (comma separated):').split(',')
|
19 |
+
|
20 |
+
if st.button('Generate Answer'):
|
21 |
+
answer = generate_answer(question, distractors)
|
22 |
+
st.write('Answer:', answer)
|