Spaces:
Sleeping
Sleeping
File size: 3,054 Bytes
662636f 23752c4 6e98be9 6110da3 313893f 23752c4 6e98be9 5f16603 8e45f12 400ddf8 bfb2729 6110da3 bfb2729 991d32c 1b40fc5 991d32c 9b49413 eb0b5b4 6e98be9 dfb1734 5f4e1e4 6110da3 dfb1734 f464384 f071ce0 b916535 f071ce0 8e45f12 518f1a5 759ea45 518f1a5 759ea45 518f1a5 759ea45 518f1a5 759ea45 518f1a5 759ea45 518f1a5 759ea45 518f1a5 759ea45 518f1a5 8e45f12 bfb2729 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import streamlit as st
import transformers
from transformers import pipeline
import PIL
from PIL import Image
import requests
from transformers import AutoProcessor, AutoModelForZeroShotImageClassification
pipe = pipeline("summarization", model="google/pegasus-xsum")
agepipe = pipeline("image-classification", model="dima806/facial_age_image_detection")
imgpipe = pipeline("zero-shot-image-classification", model="openai/clip-vit-base-patch32")
emopipe = pipeline("text-classification", model="michellejieli/emotion_text_classifier")
st.title("NLP APP")
option = st.sidebar.selectbox(
"Choose a task",
("Summarization", "Age Detection", "Emotion Detection", "Image Classification")
)
if option == "Summarization":
st.title("Text Summarization")
text = st.text_area("Enter text to summarize")
if st.button("Summarize"):
if text:
st.write("Summary:", pipe(text)[0]["summary_text"])
else:
st.write("Please enter text to summarize.")
elif option == "Age Detection":
st.title("Welcome to age detection")
uploaded_files = st.file_uploader("Choose a image file",type="jpg")
if uploaded_files is not None:
Image=Image.open(uploaded_files)
st.write("Detected age is ",agepipe(Image)[0]["label"])
elif option == "Image Classification":
st.title("Welcome to object detection")
uploaded_file = st.file_uploader("Choose an image file", type=["jpg", "jpeg", "png"])
text = st.text_area("Enter possible class names (comma-separated)")
if st.button("Submit"):
if uploaded_file is not None and text:
candidate_labels = [t.strip() for t in text.split(',')]
image = Image.open(uploaded_file)
st.image(image, caption="Uploaded Image", use_column_width=True)
classification_result = imgpipe(image, candidate_labels=candidate_labels)
for result in classification_result:
st.write(f"Label: {result['label']}, Score: {result['score']}")
else:
st.write("Please upload an image file and enter class names.")
elif option == "Emotion Detection":
st.title("Detect your emotion")
text=st.text_area("Enter your text")
if st.button("Submit"):
if text:
emotion=emopipe(text)[0]["label"]
if emotion == "sadness":
st.write("Emotion : ",emotion,"π’")
elif emotion == "joy":
st.write("Emotion : ",emotion,"π")
elif emotion == "fear":
st.write("Emotion : ",emotion,"π¨")
elif emotion == "anger":
st.write("Emotion : ",emotion,"π‘")
elif emotion == "neutral":
st.write("Emotion : ",emotion,"π")
elif emotion == "disgust":
st.write("Emotion : ",emotion,"π€’")
elif emotion == "surprise":
st.write("Emotion : ",emotion,"π²")
else:
st.write("Please enter text.")
else:
st.title("None") |