Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from utils import load_pipeline_from_huggingface | |
| def predict_sentiment(text): | |
| """ | |
| Predict sentiment of the input text using the loaded pipeline. | |
| Args: | |
| text (str): Input text to analyze | |
| Returns: | |
| str: Sentiment prediction | |
| """ | |
| try: | |
| # Load pipeline | |
| sentiment_pipeline = load_pipeline_from_huggingface() | |
| # Get prediction using pipeline | |
| results = sentiment_pipeline(text) | |
| # Extract the highest confidence prediction | |
| best_result = max(results[0], key=lambda x: x['score']) | |
| sentiment = best_result['label'] | |
| confidence = best_result['score'] | |
| return f"Sentiment: {sentiment} (Confidence: {confidence:.2f})" | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Create Gradio interface | |
| demo = gr.Interface( | |
| fn=predict_sentiment, | |
| inputs="text", | |
| outputs="text", | |
| title="Financial Sentiment Analysis", | |
| description="Enter financial text to analyze sentiment using the finetuned FinBERT model.", | |
| examples=[ | |
| "The stock market is performing well today.", | |
| "The company's earnings report was disappointing.", | |
| "Investors are optimistic about the future prospects." | |
| ] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |