Spaces:
Sleeping
Sleeping
| 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!") | |