import gradio as gr from transformers import pipeline # Load the models model1 = pipeline("sentiment-analysis", model="mrm8488/distilroberta-finetuned-financial-news-sentiment-analysis") model2 = pipeline("sentiment-analysis", model="mr8488/distilroberta-finetuned-financial-news-sentiment-analysis") # Define the function to generate responses def analyze_sentiment(input_text): result1 = model1(input_text)[0] result2 = model2(input_text)[0] return {"Model 1": f"{result1['label']} ({result1['score']:.2f})", "Model 2": f"{result2['label']} ({result2['score']:.2f})"} # Create the Gradio interface iface = gr.Interface( fn=analyze_sentiment, inputs=gr.inputs.Textbox(lines=5, label="Input Text"), outputs=[gr.outputs.Textbox(label="mrm"), gr.outputs.Textbox(label="mr")], title="Financial News Sentiment Analysis Models Comparison", description="Compare sentiment analysis results of two models." ) # Launch the interface iface.launch()