Spaces:
Sleeping
Sleeping
Upload multi_task_ai_tool.py
Browse files- multi_task_ai_tool.py +36 -0
multi_task_ai_tool.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Setting up the Streamlit app
|
| 6 |
+
st.title("Multi-Task AI Tool with Hugging Face")
|
| 7 |
+
st.write("Welcome to the Multi-Task AI Tool! This app can perform sentiment analysis, named entity recognition, and text generation.")
|
| 8 |
+
|
| 9 |
+
# User input
|
| 10 |
+
user_input = st.text_input("Enter your text below:")
|
| 11 |
+
|
| 12 |
+
if user_input:
|
| 13 |
+
# Sentiment Analysis
|
| 14 |
+
classifier = pipeline('sentiment-analysis')
|
| 15 |
+
sentiment = classifier(user_input)
|
| 16 |
+
st.subheader("Sentiment Analysis:")
|
| 17 |
+
st.write(f"Label: {sentiment[0]['label']}")
|
| 18 |
+
st.write(f"Confidence: {sentiment[0]['score']:.2f}")
|
| 19 |
+
|
| 20 |
+
# Named Entity Recognition
|
| 21 |
+
ner = pipeline('ner', grouped_entities=True)
|
| 22 |
+
entities = ner(user_input)
|
| 23 |
+
st.subheader("Named Entity Recognition:")
|
| 24 |
+
if entities:
|
| 25 |
+
for entity in entities:
|
| 26 |
+
st.write(f"Entity: {entity['entity_group']} - Word: {entity['word']} - Confidence: {entity['score']:.2f}")
|
| 27 |
+
else:
|
| 28 |
+
st.write("No named entities found.")
|
| 29 |
+
|
| 30 |
+
# Text Generation
|
| 31 |
+
text_generator = pipeline('text-generation')
|
| 32 |
+
response = text_generator(user_input, max_length=50, num_return_sequences=1)
|
| 33 |
+
st.subheader("Text Generation:")
|
| 34 |
+
st.write(response[0]['generated_text'])
|
| 35 |
+
|
| 36 |
+
st.write("Type something and see how the AI responds!")
|