arifa2399 commited on
Commit
674526c
Β·
verified Β·
1 Parent(s): 790451f

update app.py

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