Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,24 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from vit_model_test import CustomModel
|
| 4 |
|
| 5 |
+
# Initialize the model
|
| 6 |
+
model = CustomModel()
|
| 7 |
|
| 8 |
+
def predict(image: Image.Image):
|
| 9 |
+
# Get predictions from the model
|
| 10 |
+
label, confidence = model.predict(image)
|
| 11 |
+
return f"Predicted label: {label}", f"Confidence: {confidence:.2f}%"
|
| 12 |
|
| 13 |
+
# Define the Gradio interface with updated API
|
| 14 |
+
demo = gr.Interface(
|
| 15 |
+
fn=predict,
|
| 16 |
+
inputs=gr.Image(type="pil"), # Updated for new Gradio API
|
| 17 |
+
outputs=[gr.Textbox(), gr.Textbox()], # Updated for new Gradio API
|
| 18 |
+
title="Vision Transformer Model", # Title of the Gradio interface
|
| 19 |
+
description="Upload an image to classify it using the Vision Transformer model." # Description
|
| 20 |
+
)
|
| 21 |
|
| 22 |
+
# Launch the Gradio interface
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
demo.launch()
|