Spaces:
Sleeping
Sleeping
File size: 1,482 Bytes
0ceff0a 991fbeb 0ceff0a 991fbeb 0ceff0a 75f06df 991fbeb 93c87bc 991fbeb 75f06df 991fbeb 174252c 991fbeb 38b27ef 0ceff0a 991fbeb 0ceff0a 93ac46b ae6c854 991fbeb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import gradio as gr
from PIL import Image
from vit_model_test import Custom_VIT_Model # Ensure you import the correct class
# Initialize the model
model = Custom_VIT_Model()
# Variable to store the last prediction result
last_prediction = None
def predict(image: Image.Image):
global last_prediction
label, confidence = model.predict(image)
result = "AI image" if label == 1 else "Real image"
last_prediction = (image, label) # Store the image and prediction label
return result, f"Confidence: {confidence:.2f}%"
def report_feedback():
if last_prediction is not None:
image, predicted_label = last_prediction
correct_label = 1 if predicted_label == 0 else 0 # Invert the label
model.add_data(image, correct_label) # Add incorrect prediction to model
return "Feedback recorded. Thank you!"
return "No prediction available to report."
# Define the Gradio interface for prediction
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=[gr.Textbox(label="Prediction"), gr.Textbox(label="Confidence")],
title="Vision Transformer Model",
description="Upload an image to classify it using the Vision Transformer model.",
theme=gr.themes.Soft()
)
# Define the feedback button
feedback_button = gr.Button("The model was wrong")
feedback_button.click(report_feedback)
# Launch the Gradio interface
if __name__ == "__main__":
demo.launch(share=True)
feedback_button.launch() |