Pavani2704's picture
Update app.py
f071ce0 verified
raw
history blame
2.01 kB
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")
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(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)
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.")
else:
st.title("None")