Spaces:
Build error
Build error
root commited on
Commit ·
5fc0dd3
1
Parent(s): 60f7aea
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def classifyArchitecture(img):
|
| 5 |
+
# Call the model
|
| 6 |
+
image_processor = AutoImageProcessor.from_pretrained("hanslab37/architectural_styles_classifier")
|
| 7 |
+
classifier = AutoModelForImageClassification.from_pretrained("hanslab37/architectural_styles_classifier")
|
| 8 |
+
|
| 9 |
+
# Transform our image and pass it through the model
|
| 10 |
+
inputs = image_processor(image, return_tensors="pt")
|
| 11 |
+
output = classifier(**inputs)
|
| 12 |
+
|
| 13 |
+
# Display the image
|
| 14 |
+
display(img)
|
| 15 |
+
|
| 16 |
+
# Predicted Class probabilities
|
| 17 |
+
proba = output.logits.softmax(1)
|
| 18 |
+
preds = proba.argmax(1)
|
| 19 |
+
|
| 20 |
+
result = f'Predicted Architectural Styles: {classifier.config.id2label[preds.item()]} (Confidence: {proba[0][preds.item()].item()})'
|
| 21 |
+
# result = '''{
|
| 22 |
+
# score: {0},
|
| 23 |
+
# label: {1}
|
| 24 |
+
# }
|
| 25 |
+
# '''.format(proba[0][preds.item()].item(), classifier.config.id2label[preds.item()])
|
| 26 |
+
# epred = "Label: {0}, Score: {1}".format(classifier.config.id2label[i], proba[0][i].item())
|
| 27 |
+
return result
|
| 28 |
+
|
| 29 |
+
page = gr.Interface(fn=classifyArchitecture, inputs="image", outputs="text")
|
| 30 |
+
page.launch()
|