Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load model and tokenizer
|
5 |
+
model_name = "t5_history_qa"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
+
qa_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
9 |
+
|
10 |
+
# Streamlit app
|
11 |
+
st.title("History QA with T5 Model")
|
12 |
+
st.write("Enter the historical context and your question below:")
|
13 |
+
|
14 |
+
context = st.text_area("Context", height=200)
|
15 |
+
question = st.text_input("Question")
|
16 |
+
|
17 |
+
if st.button("Get Answer"):
|
18 |
+
input_text = f"question: {question} context: {context}"
|
19 |
+
result = qa_pipeline(input_text)
|
20 |
+
answer = result[0]['generated_text']
|
21 |
+
st.write("**Answer:**")
|
22 |
+
st.write(answer)
|