from transformers import pipeline import gradio as gr # Attempt to load the model and run a test prediction try: sentiment_analysis = pipeline(model=("HuggingFaceFW/fineweb-edu-classifier"))#"finiteautomata/bertweet-base-sentiment-analysis") test_output = sentiment_analysis("Testing the model with a simple sentence.") print("Model test output:", test_output) except Exception as e: print(f"Failed to load or run model: {e}") # Prediction function with error handling def predict_sentiment(text): try: predictions = sentiment_analysis(text) return f"Label: {predictions[0]['label']}, Score: {predictions[0]['score']:.4f}" except Exception as e: return f"Error processing input: {e}" # Define example inputs exams = [ "I absolutely love this product! It has changed my life.", "This is the worst movie I have ever seen. Completely disappointing.", "I'm not sure how I feel about this new update. It has some good points, but also many drawbacks.", "The customer service was fantastic! Very helpful and polite.", "Honestly, this was quite a mediocre experience. Nothing special.", "Learning new skills in mathematics can significantly improve problem-solving abilities." ] # Gradio interface setup iface = gr.Interface(fn=predict_sentiment, title="education_text_recognizer", description="Enter text to analyze education relation. Powered by Hugging Face Transformers.", inputs="text", outputs="text", examples=exams) iface.launch()