Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoFeatureExtractor, AutoModelForImageClassification
|
2 |
+
|
3 |
+
extractor = AutoFeatureExtractor.from_pretrained("saved_model_files")
|
4 |
+
model = AutoModelForImageClassification.from_pretrained("saved_model_files")
|
5 |
+
|
6 |
+
labels = ['affected', 'destroyed', 'no_damage']
|
7 |
+
|
8 |
+
def classify(im):
|
9 |
+
features = image_processor(im, return_tensors='pt')
|
10 |
+
logits = model(features["pixel_values"])[-1]
|
11 |
+
probability = torch.nn.functional.softmax(logits, dim=-1)
|
12 |
+
probs = probability[0].detach().numpy()
|
13 |
+
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
|
14 |
+
return confidences
|
15 |
+
|
16 |
import gradio as gr
|
17 |
|
|
|
|
|
18 |
|
19 |
+
interface = gr.Interface(
|
20 |
+
fn=classify,
|
21 |
+
inputs="image",
|
22 |
+
outputs="label"
|
23 |
+
)
|
24 |
+
|
25 |
+
interface.launch(share=True, debug=True)
|