# Install dependencies if not already installed # !pip install gradio transformers import gradio as gr from transformers import pipeline # Load sentiment analysis pipeline pipe = pipeline('sentiment-analysis') # For financial sentiment analysis you can use: # pipe = pipeline("text-classification", model="ProsusAI/finbert") # Define function def analyze_sentiment(text): if text.strip() == "": return {"error": "Please enter some text."} result = pipe(text) return result # Gradio Interface with gr.Blocks() as demo: gr.Markdown("## Sentiment Analysis with Transformers") with gr.Row(): text_input = gr.Textbox( label="Enter your input:", placeholder="Type text here...", lines=4 ) output = gr.JSON(label="Output") analyze_button = gr.Button("Analyze Sentiment") analyze_button.click( fn=analyze_sentiment, inputs=text_input, outputs=output ) # Launch app if __name__ == "__main__": demo.launch()