arifa2399 commited on
Commit
4cedea7
·
verified ·
1 Parent(s): efcae54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -1,18 +1,22 @@
1
-
2
-
3
-
4
  import streamlit as st
5
- from transformers import pipeline
6
  from PIL import Image
7
  import requests
8
- from transformers import AutoProcessor, AutoModelForZeroShotImageClassification
9
 
10
- # Define pipelines
11
- pipe = pipeline("summarization", model="google/pegasus-xsum")
12
- agepipe = pipeline("image-classification", model="dima806/facial_age_image_detection")
13
- imgpipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
14
- emopipe = pipeline("text-classification", model="michellejieli/emotion_text_classifier")
15
- transpipe = pipeline("translation_en_to_fr")
 
 
 
 
 
 
 
 
 
16
 
17
  st.title("NLP APP")
18
  option = st.sidebar.selectbox(
@@ -25,15 +29,15 @@ if option == "Summarization":
25
  text = st.text_area("Enter text to summarize")
26
  if st.button("Summarize"):
27
  if text:
28
- st.write("Summary:", pipe(text)[0]["summary_text"])
29
  else:
30
  st.write("Please enter text to summarize.")
31
  elif option == "Age Detection":
32
  st.title("Welcome to age detection")
33
- uploaded_files = st.file_uploader("Choose a image file", type="jpg")
34
  if uploaded_files is not None:
35
  image = Image.open(uploaded_files)
36
- st.write("Detected age is ", agepipe(image)[0]["label"])
37
  elif option == "Image Classification":
38
  st.title("Welcome to object detection")
39
  uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
@@ -43,7 +47,7 @@ elif option == "Image Classification":
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:
@@ -53,7 +57,7 @@ elif option == "Emotion Detection":
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":
@@ -75,7 +79,7 @@ elif option == "Translation":
75
  text = st.text_area("Enter text to translate from English to French")
76
  if st.button("Translate"):
77
  if text:
78
- translation = transpipe(text)[0]["translation_text"]
79
  st.write("Translation:", translation)
80
  else:
81
  st.write("Please enter text to translate.")
 
 
 
 
1
  import streamlit as st
 
2
  from PIL import Image
3
  import requests
 
4
 
5
+ # Dummy functions to simulate the behavior of the removed pipelines
6
+ def summarize(text):
7
+ return "This is a summary of the text."
8
+
9
+ def detect_age(image):
10
+ return "Age: 25-30"
11
+
12
+ def classify_image(image, candidate_labels):
13
+ return [{"label": label, "score": 0.5} for label in candidate_labels]
14
+
15
+ def detect_emotion(text):
16
+ return "joy"
17
+
18
+ def translate(text):
19
+ return "Ceci est une traduction."
20
 
21
  st.title("NLP APP")
22
  option = st.sidebar.selectbox(
 
29
  text = st.text_area("Enter text to summarize")
30
  if st.button("Summarize"):
31
  if text:
32
+ st.write("Summary:", summarize(text))
33
  else:
34
  st.write("Please enter text to summarize.")
35
  elif option == "Age Detection":
36
  st.title("Welcome to age detection")
37
+ uploaded_files = st.file_uploader("Choose an image file", type="jpg")
38
  if uploaded_files is not None:
39
  image = Image.open(uploaded_files)
40
+ st.write(detect_age(image))
41
  elif option == "Image Classification":
42
  st.title("Welcome to object detection")
43
  uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
 
47
  candidate_labels = [t.strip() for t in text.split(',')]
48
  image = Image.open(uploaded_file)
49
  st.image(image, caption="Uploaded Image", use_column_width=True)
50
+ classification_result = classify_image(image, candidate_labels)
51
  for result in classification_result:
52
  st.write(f"Label: {result['label']}, Score: {result['score']}")
53
  else:
 
57
  text = st.text_area("Enter your text")
58
  if st.button("Submit"):
59
  if text:
60
+ emotion = detect_emotion(text)
61
  if emotion == "sadness":
62
  st.write("Emotion : ", emotion, "😢")
63
  elif emotion == "joy":
 
79
  text = st.text_area("Enter text to translate from English to French")
80
  if st.button("Translate"):
81
  if text:
82
+ translation = translate(text)
83
  st.write("Translation:", translation)
84
  else:
85
  st.write("Please enter text to translate.")