Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,24 +5,17 @@ import requests
|
|
5 |
import torch
|
6 |
|
7 |
# Load model from Hugging Face model hub
|
8 |
-
model_name = "
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
model = AutoModelForImageClassification.from_pretrained(model_name)
|
11 |
|
12 |
# Define function for image preprocessing and prediction
|
13 |
def process_image(image):
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
# Make prediction
|
18 |
-
outputs = model(**inputs)
|
19 |
-
predicted_class = torch.argmax(outputs.logits, dim=1)
|
20 |
-
return predicted_class.item()
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
output = gr.outputs.Label(num_top_classes=1)
|
25 |
-
interface = gr.Interface(fn=process_image, inputs=inputs, outputs=output, capture_session=True)
|
26 |
|
27 |
-
|
28 |
-
interface.launch(share=True)
|
|
|
5 |
import torch
|
6 |
|
7 |
# Load model from Hugging Face model hub
|
8 |
+
model_name = "best20.pt" # Replace with your model's name on Hugging Face
|
9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
model = AutoModelForImageClassification.from_pretrained(model_name)
|
11 |
|
12 |
# Define function for image preprocessing and prediction
|
13 |
def process_image(image):
|
14 |
+
img_4d=img.reshape(-1,256,256,3)
|
15 |
+
prediction=Model.predict(img_4d)[0]
|
16 |
+
return {class_names[i]: float(prediction[i]) for i in range(3)}
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
image = gr.inputs.Image(shape=(256,256))
|
19 |
+
label = gr.outputs.Label(num_top_classes=3)
|
|
|
|
|
20 |
|
21 |
+
gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch()
|
|