arifa2399 commited on
Commit
cb3a65b
β€’
1 Parent(s): 5a61bcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -22
app.py CHANGED
@@ -1,21 +1,21 @@
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")
@@ -26,16 +26,12 @@ if option == "Summarization":
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"):
@@ -50,26 +46,34 @@ elif option == "Image Classification":
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")
 
1
  import streamlit as st
 
2
  from transformers import pipeline
 
3
  from PIL import Image
4
  import requests
 
5
 
6
+ # Define pipelines
7
  pipe = pipeline("summarization", model="google/pegasus-xsum")
8
  agepipe = pipeline("image-classification", model="dima806/facial_age_image_detection")
9
  imgpipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
10
  emopipe = pipeline("text-classification", model="michellejieli/emotion_text_classifier")
11
+ transpipe = pipeline("translation_en_to_fr")
12
 
13
  st.title("NLP APP")
14
  option = st.sidebar.selectbox(
15
  "Choose a task",
16
+ ("Summarization", "Age Detection", "Emotion Detection", "Image Classification", "Translation")
17
  )
18
+
19
  if option == "Summarization":
20
  st.title("Text Summarization")
21
  text = st.text_area("Enter text to summarize")
 
26
  st.write("Please enter text to summarize.")
27
  elif option == "Age Detection":
28
  st.title("Welcome to age detection")
29
+ uploaded_files = st.file_uploader("Choose an image file", type="jpg")
 
 
30
  if uploaded_files is not None:
31
+ image = Image.open(uploaded_files)
32
+ st.write("Detected age is ", agepipe(image)[0]["label"])
 
33
  elif option == "Image Classification":
34
  st.title("Welcome to object detection")
 
35
  uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
36
  text = st.text_area("Enter possible class names (comma-separated)")
37
  if st.button("Submit"):
 
46
  st.write("Please upload an image file and enter class names.")
47
  elif option == "Emotion Detection":
48
  st.title("Detect your emotion")
49
+ text = st.text_area("Enter your text")
50
  if st.button("Submit"):
51
  if text:
52
+ emotion = emopipe(text)[0]["label"]
53
  if emotion == "sadness":
54
+ st.write("Emotion : ", emotion, "😒")
55
  elif emotion == "joy":
56
+ st.write("Emotion : ", emotion, "πŸ˜ƒ")
57
  elif emotion == "fear":
58
+ st.write("Emotion : ", emotion, "😨")
59
  elif emotion == "anger":
60
+ st.write("Emotion : ", emotion, "😑")
61
  elif emotion == "neutral":
62
+ st.write("Emotion : ", emotion, "😐")
63
  elif emotion == "disgust":
64
+ st.write("Emotion : ", emotion, "🀒")
65
  elif emotion == "surprise":
66
+ st.write("Emotion : ", emotion, "😲")
67
  else:
68
  st.write("Please enter text.")
69
+ elif option == "Translation":
70
+ st.title("Text Translation")
71
+ text = st.text_area("Enter text to translate from English to French")
72
+ if st.button("Translate"):
73
+ if text:
74
+ translation = transpipe(text)[0]["translation_text"]
75
+ st.write("Translation:", translation)
76
+ else:
77
+ st.write("Please enter text to translate.")
78
  else:
79
+ st.title("None")