Spaces:
Build error
Build error
| from transformers import pipeline | |
| import gradio as gr | |
| # Initialize the pipeline with TensorFlow | |
| pipe = pipeline("text-classification", model="ZachBeesley/Spam-Detector", framework="tf") | |
| # Function to process the input text and return the predicted label | |
| def predict(text): | |
| try: | |
| # Use the pipeline to classify the text | |
| result = pipe(text) | |
| # Extract the predicted label and confidence score | |
| label = result[0]["label"] | |
| confidence = result[0]["score"] | |
| # Return the result | |
| return f"Predicted label: {label}\nConfidence: {confidence:.2f}" | |
| except Exception as e: | |
| # Handle errors | |
| return f"Error: {str(e)}" | |
| # Create the Gradio interface | |
| iface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(label="Email Text", placeholder="Paste your email text here..."), | |
| outputs="text", | |
| title="Spam Email Detector", | |
| description="Enter an email and find out if it's spam or not." | |
| ) | |
| # Launch the interface | |
| iface.launch() | |