File size: 1,286 Bytes
45b5d1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import streamlit as st
from transformers import pipeline

# Setting up the Streamlit app
st.title("Multi-Task AI Tool with Hugging Face")
st.write("Welcome to the Multi-Task AI Tool! This app can perform sentiment analysis, named entity recognition, and text generation.")

# User input
user_input = st.text_input("Enter your text below:")

if user_input:
    # Sentiment Analysis
    classifier = pipeline('sentiment-analysis')
    sentiment = classifier(user_input)
    st.subheader("Sentiment Analysis:")
    st.write(f"Label: {sentiment[0]['label']}")
    st.write(f"Confidence: {sentiment[0]['score']:.2f}")

    # Named Entity Recognition
    ner = pipeline('ner', grouped_entities=True)
    entities = ner(user_input)
    st.subheader("Named Entity Recognition:")
    if entities:
        for entity in entities:
            st.write(f"Entity: {entity['entity_group']} - Word: {entity['word']} - Confidence: {entity['score']:.2f}")
    else:
        st.write("No named entities found.")

    # Text Generation
    text_generator = pipeline('text-generation')
    response = text_generator(user_input, max_length=50, num_return_sequences=1)
    st.subheader("Text Generation:")
    st.write(response[0]['generated_text'])

st.write("Type something and see how the AI responds!")