danielspba commited on
Commit
2ffec9c
·
verified ·
1 Parent(s): e93f0fc

Upload 3 files

Browse files
modelo_quantizado16bits.tflite ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b811b8ad7116a501259ac5bbb9fbaefb783a03726ddc7fbed4232a87d0cfbf03
3
+ size 326262764
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ tensorflow
4
+ pillow
5
+ pandas
6
+ plotly
7
+ gdown
soulcode_daniel_app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Soulcode - Daniel - app
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/13peJNRQ1u9QyZ2VueTA7vDPoQ6Q7QcQO
8
+ """
9
+
10
+ import gradio as gr
11
+ from PIL import Image
12
+ import numpy as np
13
+ import tensorflow as tf
14
+ import pandas as pd
15
+ import plotly.express as px
16
+ import gdown
17
+ import os
18
+
19
+ # Carrega o modelo TFLite uma única vez
20
+ def carrega_modelo():
21
+ output = 'modelo_quantizado16bits.tflite'
22
+
23
+ if not os.path.exists(output):
24
+ raise FileNotFoundError("O modelo TFLite não foi encontrado no diretório do app.")
25
+
26
+ interpreter = tf.lite.Interpreter(model_path=output)
27
+ interpreter.allocate_tensors()
28
+ return interpreter
29
+
30
+ interpreter = carrega_modelo()
31
+
32
+ # Função principal que recebe a imagem e retorna o gráfico
33
+ def classificar_imagem(imagem_pil):
34
+ # Pré-processamento da imagem
35
+ image = np.array(imagem_pil, dtype=np.float32)
36
+ image = image / 255.0
37
+ image = np.expand_dims(image, axis=0)
38
+
39
+ # Realiza inferência
40
+ input_details = interpreter.get_input_details()
41
+ output_details = interpreter.get_output_details()
42
+ interpreter.set_tensor(input_details[0]['index'], image)
43
+ interpreter.invoke()
44
+ output_data = interpreter.get_tensor(output_details[0]['index'])
45
+
46
+ # Processa saída e cria gráfico
47
+ classes = ['BlackMeasles', 'BlackRot', 'HealthyGrapes', 'LeafBlight']
48
+ df = pd.DataFrame({'classes': classes, 'probabilidades (%)': 100 * output_data[0]})
49
+ fig = px.bar(df, y='classes', x='probabilidades (%)', orientation='h', text='probabilidades (%)',
50
+ title='Probabilidade de Classes de Doenças em Uvas')
51
+ return fig
52
+
53
+ # Interface Gradio
54
+ interface = gr.Interface(
55
+ fn=classificar_imagem,
56
+ inputs=gr.Image(type="pil", label="Envie uma imagem de folha de videira"),
57
+ outputs=gr.Plot(label="Gráfico de Previsões"),
58
+ title="Classificador de Folhas de Videira 🍇",
59
+ description="Faça upload de uma imagem de folha de videira para detectar possíveis doenças."
60
+ )
61
+
62
+ if __name__ == "__main__":
63
+ interface.launch()