File size: 1,885 Bytes
b1df8b4
 
dc13db1
 
 
b1df8b4
 
 
dc13db1
b1df8b4
dc13db1
b1df8b4
 
 
 
 
 
 
 
 
 
 
 
 
 
dc13db1
 
 
 
 
b1df8b4
 
dc13db1
b1df8b4
 
 
dc13db1
 
 
 
 
b1df8b4
 
 
 
 
 
dc13db1
 
 
 
 
 
b1df8b4
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
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