import gradio as gr from transformers import pipeline # Load the text classification pipeline pipeline = pipeline("text-classification", model="ProsusAI/finbert", trust_remote_code=True) def predict(input_text): predictions = pipeline(input_text, threshold=0.5, return_scores=True) return predictions[0] gradio_app = gr.Interface( predict, inputs=gr.Textbox(label="Write a text"), outputs=None, components=[ gr.Label(label="Label: {}".format(predictions[0]["label"])), gr.Label(label="Score: {:.2f}".format(predictions[0]["score"][0])), ], title="Financial Sentiment Analysis", ) # Launch the Gradio interface if __name__ == "__main__": gradio_app.launch()