Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,42 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 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 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Summarization
|
| 5 |
+
def summarization(image_path):
|
| 6 |
+
with open(image_path, "rb") as image_file:
|
| 7 |
+
bytes_data = image_file.read()
|
| 8 |
+
image_to_text_model = pipeline("text-generation", model="ainize/bart-base-cnn")
|
| 9 |
+
summary = image_to_text_model(bytes_data, max_length=100, do_sample=False)[0]["generated_text"]
|
| 10 |
+
return summary
|
| 11 |
|
| 12 |
+
# Sentiment Classification
|
| 13 |
+
def sentiment_classification(summary):
|
| 14 |
+
sentiment_model = pipeline("text-classification", model="wxrrrrrrr/finetuned_sentiment_analysis")
|
| 15 |
+
result = sentiment_model(summary, max_length=100, do_sample=False)[0]['label']
|
| 16 |
+
return result
|
| 17 |
|
| 18 |
+
def main():
|
| 19 |
+
st.set_page_config(page_title="Your Image to Text Analysis", page_icon="🦜")
|
| 20 |
+
st.header("Tell me your comments!")
|
| 21 |
+
uploaded_file = st.file_uploader("Select an Image...")
|
| 22 |
|
| 23 |
+
if uploaded_file is not None:
|
| 24 |
+
with open(uploaded_file.name, "wb") as file:
|
| 25 |
+
file.write(uploaded_file.getbuffer())
|
| 26 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 27 |
|
| 28 |
+
# Stage 1: Summarization
|
| 29 |
+
st.text('Processing image to text...')
|
| 30 |
+
summary = summarization(uploaded_file.name)
|
| 31 |
+
st.write(summary)
|
| 32 |
|
| 33 |
+
# Stage 2: Sentiment Classification
|
| 34 |
+
st.text('Analyzing sentiment...')
|
| 35 |
+
sentiment = sentiment_classification(summary)
|
| 36 |
+
st.write(sentiment)
|
| 37 |
|
| 38 |
+
# Display the classification result
|
| 39 |
+
st.write("Sentiment:", sentiment)
|
| 40 |
+
|
| 41 |
+
if __name__ == '__main__':
|
| 42 |
+
main()
|