Cynthiaaaaaaaa commited on
Commit
75d6c8e
·
verified ·
1 Parent(s): c27e90c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -21
app.py CHANGED
@@ -1,30 +1,42 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- # Load the text classification model pipeline
5
- classifier = pipeline("text-classification",model='wxrrrrrrr/finetunde_sentiment_analysis', return_all_scores=True)
 
 
 
 
 
6
 
7
- # Streamlit application title
8
- st.title("Text Sentiment")
9
- st.write("Analysis for 2 emotions: love, anger")
 
 
10
 
11
- # Text input for user to enter the text to classify
12
- text = st.text_area("Enter the text to analysis", "")
 
 
13
 
14
- # Perform text classification when the user clicks the "Classify" button
15
- if st.button("Analysis"):
16
- # Perform text classification on the input text
17
- results = classifier(text)[0]
18
 
19
- # Display the classification result
20
- max_score = float('-inf')
21
- max_label = ''
 
22
 
23
- for result in results:
24
- if result['score'] > max_score:
25
- max_score = result['score']
26
- max_label = result['label']
27
 
28
- st.write("Text:", text)
29
- st.write("Label:", max_label)
30
- st.write("Score:", max_score)
 
 
 
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()