Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the sentiment analysis and named entity recognition pipelines from Hugging Face Transformers | |
| sentiment_analyzer = pipeline('sentiment-analysis') | |
| ner_analyzer = pipeline('ner') | |
| # Function to perform multiple analyses on text | |
| def analyze_text(text): | |
| # Sentiment analysis | |
| sentiment_result = sentiment_analyzer(text)[0] | |
| sentiment_analysis = f"Sentiment: {sentiment_result['label']} ({sentiment_result['score']:.2f})" | |
| # Named Entity Recognition (NER) | |
| ner_results = ner_analyzer(text) | |
| ner_analysis = "Named Entities:\n" + "\n".join([f"{entity['word']} ({entity['entity']})" for entity in ner_results]) | |
| return sentiment_analysis + "\n\n" + ner_analysis | |
| # Create a Gradio interface | |
| iface = gr.Interface(fn=analyze_text, inputs="text", outputs="text") | |
| # Launch the Gradio app | |
| iface.launch() | |