Spaces:
Build error
Build error
import streamlit as st | |
from transformers import pipeline | |
from PIL import Image | |
import requests | |
from io import BytesIO | |
# Load models for different tasks | |
summarizer = pipeline("summarization", model="google/pegasus-xsum") | |
translator = pipeline("translation_en_to_fr") | |
emotion_detector = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") | |
# Note: Ensure you have the correct pipeline and model for image generation | |
st.title("NLP and Image Processing App") | |
# Sidebar options | |
option = st.sidebar.selectbox( | |
"Choose a task", | |
("Summarization", "Translation", "Emotion Detection", "Image Generation") | |
) | |
# Summarization | |
if option == "Summarization": | |
st.header("Text Summarization") | |
text = st.text_area("Enter text to summarize") | |
if st.button("Summarize"): | |
if text: | |
summary = summarizer(text)[0]["summary_text"] | |
st.write("Summary:", summary) | |
else: | |
st.write("Please enter text to summarize.") | |
# Translation | |
elif option == "Translation": | |
st.header("Language Translation (English to French)") | |
text = st.text_area("Enter text to translate") | |
if st.button("Translate"): | |
if text: | |
translation = translator(text)[0]["translation_text"] | |
st.write("Translation:", translation) | |
else: | |
st.write("Please enter text to translate.") | |
# Emotion Detection | |
elif option == "Emotion Detection": | |
st.header("Emotion Detection") | |
text = st.text_area("Enter text to detect emotion") | |
if st.button("Detect Emotion"): | |
if text: | |
emotions = emotion_detector(text) | |
for emotion in emotions: | |
st.write(f"Label: {emotion['label']}, Score: {emotion['score']}") | |
else: | |
st.write("Please enter text to detect emotion.") | |
# To run the app, use `streamlit run app.py` in your terminal | |