Rafa-bork commited on
Commit
e8b9365
·
1 Parent(s): e99a6f6

inicial commit

Browse files
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ venv
2
+ models
.gradio/flagged/dataset1.csv ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ image,Classe prevista,timestamp
2
+ "{""background"": "".gradio\\flagged\\image\\2fa0d477d3d7a47e41e4\\background.png"", ""layers"": ["".gradio\\flagged\\image\\3a5f4694877ab3c14fcb\\layer_0.png""], ""composite"": "".gradio\\flagged\\image\\b6d8ebce78d56bf966d8\\composite.png"", ""id"": null}",,2025-06-19 13:51:31.311676
3
+ "{""background"": "".gradio\\flagged\\image\\3c05ae06f88de6e976f6\\background.png"", ""layers"": ["".gradio\\flagged\\image\\782b7ede3eb388a3b583\\layer_0.png""], ""composite"": "".gradio\\flagged\\image\\1b4feabd698cceec7ebf\\composite.png"", ""id"": null}",,2025-06-19 13:58:44.445782
4
+ "{""background"": "".gradio\\flagged\\image\\dc7898043f6e7a661667\\background.png"", ""layers"": ["".gradio\\flagged\\image\\56d2383e839f42f253e4\\layer_0.png""], ""composite"": "".gradio\\flagged\\image\\58839e1b29750e1c9af7\\composite.png"", ""id"": null}",,2025-06-19 14:02:14.136177
5
+ "{""background"": "".gradio\\flagged\\image\\ef5108db4c6b89664191\\background.png"", ""layers"": ["".gradio\\flagged\\image\\0206e03a92fece916018\\layer_0.png""], ""composite"": "".gradio\\flagged\\image\\e4bc1f7342505dd9f966\\composite.png"", ""id"": null}",,2025-06-19 14:05:11.896509
.gradio/flagged/dataset2.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ image,output,timestamp
2
+ "{""background"": "".gradio\\flagged\\image\\72b571c1cc3a3abf0707\\background.png"", ""layers"": ["".gradio\\flagged\\image\\70b10cc9d3e368757c03\\layer_0.png""], ""composite"": "".gradio\\flagged\\image\\b175b154315f90d20bd5\\composite.png"", ""id"": null}","{""label"": null, ""confidences"": null}",2025-06-19 15:01:06.418014
.gradio/flagged/image/0206e03a92fece916018/layer_0.png ADDED
.gradio/flagged/image/1b4feabd698cceec7ebf/composite.png ADDED
.gradio/flagged/image/2fa0d477d3d7a47e41e4/background.png ADDED
.gradio/flagged/image/3a5f4694877ab3c14fcb/layer_0.png ADDED
.gradio/flagged/image/3c05ae06f88de6e976f6/background.png ADDED
.gradio/flagged/image/56d2383e839f42f253e4/layer_0.png ADDED
.gradio/flagged/image/58839e1b29750e1c9af7/composite.png ADDED
.gradio/flagged/image/70b10cc9d3e368757c03/layer_0.png ADDED
.gradio/flagged/image/72b571c1cc3a3abf0707/background.png ADDED
.gradio/flagged/image/782b7ede3eb388a3b583/layer_0.png ADDED
.gradio/flagged/image/b175b154315f90d20bd5/composite.png ADDED
.gradio/flagged/image/b6d8ebce78d56bf966d8/composite.png ADDED
.gradio/flagged/image/dc7898043f6e7a661667/background.png ADDED
.gradio/flagged/image/e4bc1f7342505dd9f966/composite.png ADDED
.gradio/flagged/image/ef5108db4c6b89664191/background.png ADDED
README.md DELETED
@@ -1,12 +0,0 @@
1
- ---
2
- title: Placeholder2
3
- emoji: 🏢
4
- colorFrom: green
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.34.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from torchvision import transforms
4
+ import torch.nn.functional as F
5
+ from PIL import Image
6
+
7
+ # Caminho do modelo
8
+ model_path = "models/simple_cnn_jit_epoch_10.pt"
9
+
10
+ # Pré-processamento
11
+ transform = transforms.Compose([
12
+ transforms.Resize((8, 8)),
13
+ transforms.ToTensor(),
14
+ transforms.Lambda(lambda x: 1 - x)
15
+ ])
16
+
17
+ # Carregar o modelo JIT
18
+ model = torch.jit.load(model_path, map_location="cpu")
19
+ model.eval()
20
+
21
+ # Função de predição
22
+ def predict(inputs):
23
+ pil_img = Image.fromarray(inputs['composite'])
24
+ image = transform(pil_img).unsqueeze(0)
25
+ print(image)
26
+ with torch.no_grad():
27
+ output = model(image)
28
+ probs = F.softmax(output, dim=1).squeeze().cpu().numpy()
29
+ print(probs)
30
+ labels = [str(i) for i in range(len(probs))]
31
+ print(labels)
32
+ result = {label: float(prob) for label, prob in zip(labels, probs)}
33
+ print(result)
34
+ return result
35
+
36
+ # Interface Gradio
37
+ demo = gr.Interface(
38
+ fn=predict,
39
+ inputs=gr.Sketchpad(crop_size=(256,256), type='numpy', image_mode='L', brush=gr.Brush(color_mode="fixed", colors=['#000000']), layers=False, show_label=False),
40
+ outputs=gr.Label(show_label=False, num_top_classes=7),
41
+ examples=["examples/digit1.png", "examples/digit2.png", "examples/digit3.png", "examples/digit4.png", "examples/digit5.png", "examples/digit6.png", "examples/digit7.png", "examples/digit8.png", "examples/digit9.png"],
42
+ title="Number Classification",
43
+ description="Number classification using a simple CNN model trained on the MNIST dataset. Draw a digit in the sketchpad or select from the examples and click 'Submit' to classify it.",
44
+ )
45
+
46
+ demo.launch()
examples/digit0.png ADDED
examples/digit1.png ADDED
examples/digit2.png ADDED
examples/digit3.png ADDED
examples/digit4.png ADDED
examples/digit5.png ADDED
examples/digit6.png ADDED
examples/digit7.png ADDED
examples/digit8.png ADDED
examples/digit9.png ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ torch
3
+ torchvision
4
+ PIL