import gradio as gr from transformers import pipeline # Load the model from Hugging Face Hub model_repo = "Ahmed-El-Sharkawy/my-sentiment-model" # Replace with your actual repo name nlp_pipeline = pipeline("text-classification", model=model_repo) # Gradio app function def classify_text(input_text): if input_text.strip() == "": return "Please enter some text." result = nlp_pipeline(input_text) label = result[0]['label'] score = result[0]['score'] # Map Hugging Face labels to readable format label_map = {'LABEL_0': "Negative", 'LABEL_1': "Positive"} mapped_label = label_map.get(label, label) return f"Prediction: {mapped_label}, Confidence Score: {score:.4f}" # Gradio interface iface = gr.Interface( fn=classify_text, inputs="text", outputs="text", title="Text Classification App", description="Classify text as Positive (1) or Negative (0)" ) # Launch the app iface.launch()