arifa2399 commited on
Commit
5a61bcf
Β·
verified Β·
1 Parent(s): 6feaf99

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import transformers
3
+ from transformers import pipeline
4
+ import PIL
5
+ from PIL import Image
6
+ import requests
7
+ from transformers import AutoProcessor, AutoModelForZeroShotImageClassification
8
+
9
+ pipe = pipeline("summarization", model="google/pegasus-xsum")
10
+ agepipe = pipeline("image-classification", model="dima806/facial_age_image_detection")
11
+ imgpipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
12
+ emopipe = pipeline("text-classification", model="michellejieli/emotion_text_classifier")
13
+
14
+ st.title("NLP APP")
15
+ option = st.sidebar.selectbox(
16
+ "Choose a task",
17
+ ("Summarization", "Age Detection", "Emotion Detection", "Image Classification")
18
+ )
19
+ if option == "Summarization":
20
+ st.title("Text Summarization")
21
+ text = st.text_area("Enter text to summarize")
22
+ if st.button("Summarize"):
23
+ if text:
24
+ st.write("Summary:", pipe(text)[0]["summary_text"])
25
+ else:
26
+ st.write("Please enter text to summarize.")
27
+ elif option == "Age Detection":
28
+ st.title("Welcome to age detection")
29
+
30
+ uploaded_files = st.file_uploader("Choose a image file",type="jpg")
31
+
32
+ if uploaded_files is not None:
33
+ Image=Image.open(uploaded_files)
34
+
35
+ st.write("Detected age is ",agepipe(Image)[0]["label"])
36
+ elif option == "Image Classification":
37
+ st.title("Welcome to object detection")
38
+
39
+ uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
40
+ text = st.text_area("Enter possible class names (comma-separated)")
41
+ if st.button("Submit"):
42
+ if uploaded_file is not None and text:
43
+ candidate_labels = [t.strip() for t in text.split(',')]
44
+ image = Image.open(uploaded_file)
45
+ st.image(image, caption="Uploaded Image", use_column_width=True)
46
+ classification_result = imgpipe(image, candidate_labels=candidate_labels)
47
+ for result in classification_result:
48
+ st.write(f"Label: {result['label']}, Score: {result['score']}")
49
+ else:
50
+ st.write("Please upload an image file and enter class names.")
51
+ elif option == "Emotion Detection":
52
+ st.title("Detect your emotion")
53
+ text=st.text_area("Enter your text")
54
+ if st.button("Submit"):
55
+ if text:
56
+ emotion=emopipe(text)[0]["label"]
57
+ if emotion == "sadness":
58
+ st.write("Emotion : ",emotion,"😒")
59
+ elif emotion == "joy":
60
+ st.write("Emotion : ",emotion,"πŸ˜ƒ")
61
+ elif emotion == "fear":
62
+ st.write("Emotion : ",emotion,"😨")
63
+ elif emotion == "anger":
64
+ st.write("Emotion : ",emotion,"😑")
65
+ elif emotion == "neutral":
66
+ st.write("Emotion : ",emotion,"😐")
67
+ elif emotion == "disgust":
68
+ st.write("Emotion : ",emotion,"🀒")
69
+ elif emotion == "surprise":
70
+ st.write("Emotion : ",emotion,"😲")
71
+ else:
72
+ st.write("Please enter text.")
73
+
74
+ else:
75
+ st.title("None")