VIT_Demo / app.py
litav's picture
Update app.py
40ee638 verified
raw
history blame
1.13 kB
import gradio as gr
from PIL import Image
from vit_model_test import CustomModel
# Initialize the model
model = CustomModel()
def predict(image: Image.Image):
# ื›ืืŸ ืžืชื‘ืฆืข ืขื™ื‘ื•ื“ ื”ืชืžื•ื ื”
label, confidence = model.predict(image)
result = "AI image" if label == 1 else "Real image"
return result, f"Confidence: {confidence:.2f}%"
# ื™ืฆื™ืจืช ืžืžืฉืง Gradio ืขื ื•ื™ื“ืื• ืฉืžื•ืฆื’ ื‘ื–ืžืŸ ื—ื™ืฉื•ื‘ ื”ืžื•ื“ืœ
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs=[gr.Textbox(), gr.Textbox()],
title="Vision Transformer Model",
description="Upload an image to classify it as AI-generated or Real.",
live=True, # ืžืืคืฉืจ ืœื”ืฆื™ื’ ืกื˜ื˜ื•ืก ื‘ื–ืžืŸ ืืžืช
theme="compact", # ืืคืฉืจื™ ืœื”ื•ืกื™ืฃ ืขื™ืฆื•ื‘ ืžืงืฆื•ืขื™
css=".loading-message { display: none; }"
)
# ื”ื’ื“ืจืช ื”ืกืจื˜ื•ืŸ ืฉื™ื•ืคื™ืข ื‘ื–ืžืŸ ื—ื™ืฉื•ื‘
demo.loading = "https://cdn-uploads.huggingface.co/production/uploads/66d6f1b3b50e35e1709bfdf7/x7Ud8PO9QPfmrTvBVcCKE.mp4" # ื”ื•ืกืฃ ืืช ืฉื ืงื•ื‘ืฅ ื”ื•ื•ื™ื“ืื•
# ื”ืฉืงืช ื”ืžืžืฉืง
demo.launch()