chayanee commited on
Commit
fc64992
·
1 Parent(s): 8803f6c

Upload app (3).py

Browse files
Files changed (1) hide show
  1. app (3).py +20 -23
app (3).py CHANGED
@@ -1,36 +1,33 @@
1
  import streamlit as st
2
  from PIL import Image
3
- from io import StringIO
4
  import pandas as pd
5
  from transformers import pipeline
6
 
7
- # Create an object detection pipeline
8
- classifier = pipeline("object-detection", model="chayanee/Detected_img")
9
 
10
- def main():
11
- st.title("Object Detection on Images")
12
 
13
- # File Upload Widget
14
- uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "png", "jpeg"])
15
 
16
- if uploaded_file is not None:
17
- # Display the uploaded image
18
- st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
19
-
20
- # Perform object detection
21
- image = Image.open(uploaded_file)
22
- results = classifier(image)
23
 
24
- # Display object detection results
25
- st.subheader("Object Detection Results")
26
- for result in results:
27
- label = result["label"]
28
- score = result["score"]
29
- box = result["box"]
30
- st.write(f"Label: {label}, Score: {score:.2f}")
31
- st.image(image.crop(box), caption=f"Object: {label}", use_column_width=True)
32
 
33
- st.button("Click to Detect Objects", type="primary")
 
 
 
 
34
 
35
  if __name__ == "__main__":
36
  main()
 
1
  import streamlit as st
2
  from PIL import Image
 
3
  import pandas as pd
4
  from transformers import pipeline
5
 
6
+ # Create a sentiment analysis pipeline
7
+ sentiment_analysis = pipeline("sentiment-analysis", model="chayanee/Detected_img")
8
 
9
+ # Set the title for your Streamlit app
10
+ st.title("NLP and Image Analysis")
11
 
12
+ # Text Input Widget
13
+ text_input = st.text_area("Enter some text for sentiment analysis:")
14
 
15
+ # Image Upload Widget
16
+ uploaded_image = st.file_uploader("Upload an image for analysis", type=["jpg", "jpeg", "png"])
 
 
 
 
 
17
 
18
+ # Perform sentiment analysis when the user clicks a button
19
+ if st.button("Analyze"):
20
+ # Perform sentiment analysis on the text
21
+ if text_input:
22
+ sentiment_result = sentiment_analysis(text_input)
23
+ st.write("Sentiment Analysis Result:")
24
+ st.write(sentiment_result)
 
25
 
26
+ # Analyze the uploaded image if available
27
+ if uploaded_image:
28
+ # Display the uploaded image
29
+ image = Image.open(uploaded_image)
30
+ st.image(image, caption="Uploaded Image", use_column_width=True)
31
 
32
  if __name__ == "__main__":
33
  main()