Spaces:
Sleeping
Sleeping
File size: 1,679 Bytes
9d9eafb 83ce241 c0fe54b 9d9eafb 83ce241 c0fe54b 83ce241 c0fe54b 1d4cee9 83ce241 c0fe54b 83ce241 1d4cee9 c0fe54b 1d4cee9 c0fe54b 1d4cee9 c0fe54b 1d4cee9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
import altair as alt
from transformers import pipeline
from transformers import AutoModelForSeq2SeqLM , AutoTokenizer, TranslationPipeline
from PIL import Image
st.title("Image-Based Question Answering 🕵️♂️")
st.subheader("Ask questions directly from images!")
st.write("""
Upload an image (e.g., receipts, documents), type your question, and get precise answers in real-time.
Powered by the advanced `naver-clova-ix/donut-base-finetuned-docvqa` model.
""")
# context_input = st.text_area("please provice some context", "Many NLP tasks are now benchmarked using datasets like GLUE and SuperGLUE. Multilingual NLP models like mBERT support multiple languages in a single framework.")
# question_input = st.text_area("enter question about NLP", "what model support multilingual nlp?")
@st.cache_resource
def load_model():
print("Loading model...")
return pipeline("document-question-answering", model="naver-clova-ix/donut-base-finetuned-docvqa")
dunno_answerer = load_model()
# with open('NLP_History_and_Facts.txt', 'r') as file:
# context = file.read()
uploaded_image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
if uploaded_image is not None:
image = Image.open(uploaded_image)
st.image(image, caption="Uploaded Image", use_column_width=True)
question_input = st.text_area("Enter your question", "Any questions ?")
if st.button("Answer!"):
if question_input.strip():
result = dunno_answerer(image=image, question=question_input)
st.write(f"**Answer:** {result[0]['answer']}")
else:
st.write("Please enter a valid question!")
|