Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,36 @@
|
|
| 1 |
-
# import part
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline
|
| 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 |
-
st.image(uploaded_file, caption="Uploaded Image",
|
| 39 |
-
use_column_width=True)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
#Stage 1: Image to Text
|
| 43 |
-
st.text('Processing img2text...')
|
| 44 |
-
scenario = img2text(uploaded_file.name)
|
| 45 |
-
st.write(scenario)
|
| 46 |
-
|
| 47 |
-
#Stage 2: Text to Story
|
| 48 |
-
st.text('Generating a story...')
|
| 49 |
-
#story = text2story(scenario)
|
| 50 |
-
#st.write(story)
|
| 51 |
-
|
| 52 |
-
#Stage 3: Story to Audio data
|
| 53 |
-
#st.text('Generating audio data...')
|
| 54 |
-
#audio_data =text2audio(story)
|
| 55 |
-
|
| 56 |
-
# Play button
|
| 57 |
-
if st.button("Play Audio"):
|
| 58 |
-
#st.audio(audio_data['audio'],
|
| 59 |
-
# format="audio/wav",
|
| 60 |
-
# start_time=0,
|
| 61 |
-
# sample_rate = audio_data['sampling_rate'])
|
| 62 |
-
st.audio("kids_playing_audio.wav")
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
# Set the title of the app
|
| 6 |
+
st.title("Image-to-Text Converter using Donut")
|
| 7 |
+
|
| 8 |
+
# Description of the app
|
| 9 |
+
st.write("Upload an image to extract text using the Donut model (naver-clova-ix/donut-base).")
|
| 10 |
+
|
| 11 |
+
# Create a file uploader for image files
|
| 12 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 13 |
+
|
| 14 |
+
# Initialize the pipeline
|
| 15 |
+
@st.cache_resource(show_spinner=False)
|
| 16 |
+
def load_pipeline():
|
| 17 |
+
return pipeline("image-to-text", model="naver-clova-ix/donut-base")
|
| 18 |
+
|
| 19 |
+
pipe = load_pipeline()
|
| 20 |
+
|
| 21 |
+
if uploaded_file is not None:
|
| 22 |
+
try:
|
| 23 |
+
# Open the image file and convert to RGB (if necessary)
|
| 24 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 25 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 26 |
+
|
| 27 |
+
# Process the image through the pipeline
|
| 28 |
+
result = pipe(image)
|
| 29 |
+
|
| 30 |
+
# Extract generated text from the result list
|
| 31 |
+
generated_text = result[0].get("generated_text", "No text generated.")
|
| 32 |
+
|
| 33 |
+
st.subheader("Extracted Text")
|
| 34 |
+
st.text_area("Result", generated_text, height=200)
|
| 35 |
+
except Exception as e:
|
| 36 |
+
st.error(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|