Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import
|
3 |
-
ViTImageProcessor,
|
4 |
-
ViTForImageClassification,
|
5 |
-
AutoImageProcessor,
|
6 |
-
Swin2ForImageClassification
|
7 |
-
)
|
8 |
from PIL import Image
|
9 |
import torch
|
10 |
import warnings
|
@@ -12,16 +7,12 @@ warnings.filterwarnings("ignore")
|
|
12 |
|
13 |
class IridologyAnalyzer:
|
14 |
def __init__(self):
|
15 |
-
# Inicializar
|
16 |
-
print("Carregando
|
17 |
|
18 |
# ViT model - Modelo público para análise de imagens
|
19 |
-
self.
|
20 |
-
self.
|
21 |
-
|
22 |
-
# Swin2 model - Outro modelo público para análise de imagens
|
23 |
-
self.swin_processor = AutoImageProcessor.from_pretrained("microsoft/swin-base-patch4-window7-224")
|
24 |
-
self.swin_model = Swin2ForImageClassification.from_pretrained("microsoft/swin-base-patch4-window7-224")
|
25 |
|
26 |
# Características de iridologia para análise
|
27 |
self.iris_features = [
|
@@ -39,39 +30,22 @@ class IridologyAnalyzer:
|
|
39 |
"Borda da íris"
|
40 |
]
|
41 |
|
42 |
-
print("
|
43 |
-
|
44 |
-
def analyze_with_vit(self, image):
|
45 |
-
"""Analisa a imagem usando o modelo ViT."""
|
46 |
-
inputs = self.vit_processor(images=image, return_tensors="pt")
|
47 |
-
outputs = self.vit_model(**inputs)
|
48 |
-
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
49 |
-
confidence = probs.max().item()
|
50 |
-
return confidence
|
51 |
|
52 |
-
def
|
53 |
-
"""Analisa
|
54 |
-
inputs = self.
|
55 |
-
outputs = self.
|
56 |
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
57 |
confidence = probs.max().item()
|
58 |
-
return confidence
|
59 |
-
|
60 |
-
def analyze_feature(self, image, feature):
|
61 |
-
"""Analisa uma característica específica da íris."""
|
62 |
-
vit_conf = self.analyze_with_vit(image)
|
63 |
-
swin_conf = self.analyze_with_swin(image)
|
64 |
-
|
65 |
-
# Combina os resultados dos dois modelos
|
66 |
-
avg_conf = (vit_conf + swin_conf) / 2
|
67 |
|
68 |
-
#
|
69 |
-
if
|
70 |
-
return "Alta presença"
|
71 |
-
elif
|
72 |
-
return "Presença moderada"
|
73 |
else:
|
74 |
-
return "Baixa presença"
|
75 |
|
76 |
def comprehensive_analysis(self, image):
|
77 |
"""Realiza uma análise completa da íris."""
|
@@ -79,7 +53,7 @@ class IridologyAnalyzer:
|
|
79 |
|
80 |
for feature in self.iris_features:
|
81 |
try:
|
82 |
-
analysis = self.
|
83 |
results.append({
|
84 |
"feature": feature,
|
85 |
"analysis": analysis
|
@@ -121,7 +95,7 @@ def create_gradio_interface():
|
|
121 |
outputs=gr.Textbox(label="Resultados da Análise", lines=20),
|
122 |
title="Analisador de Iridologia com IA",
|
123 |
description="""
|
124 |
-
Este sistema analisa imagens de íris usando
|
125 |
Faça o upload de uma imagem clara do olho para análise.
|
126 |
|
127 |
Recomendações para melhores resultados:
|
@@ -138,4 +112,4 @@ def create_gradio_interface():
|
|
138 |
|
139 |
if __name__ == "__main__":
|
140 |
iface = create_gradio_interface()
|
141 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import ViTImageProcessor, ViTForImageClassification
|
|
|
|
|
|
|
|
|
|
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
import warnings
|
|
|
7 |
|
8 |
class IridologyAnalyzer:
|
9 |
def __init__(self):
|
10 |
+
# Inicializar modelo
|
11 |
+
print("Carregando modelo...")
|
12 |
|
13 |
# ViT model - Modelo público para análise de imagens
|
14 |
+
self.processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
|
15 |
+
self.model = ViTForImageClassification.from_pretrained("google/vit-base-patch16-224")
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Características de iridologia para análise
|
18 |
self.iris_features = [
|
|
|
30 |
"Borda da íris"
|
31 |
]
|
32 |
|
33 |
+
print("Modelo carregado com sucesso!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
def analyze_image_feature(self, image, feature):
|
36 |
+
"""Analisa uma característica específica da íris."""
|
37 |
+
inputs = self.processor(images=image, return_tensors="pt")
|
38 |
+
outputs = self.model(**inputs)
|
39 |
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
40 |
confidence = probs.max().item()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
# Interpretação baseada na confiança do modelo
|
43 |
+
if confidence > 0.8:
|
44 |
+
return "Alta presença/intensidade"
|
45 |
+
elif confidence > 0.5:
|
46 |
+
return "Presença/intensidade moderada"
|
47 |
else:
|
48 |
+
return "Baixa presença/intensidade"
|
49 |
|
50 |
def comprehensive_analysis(self, image):
|
51 |
"""Realiza uma análise completa da íris."""
|
|
|
53 |
|
54 |
for feature in self.iris_features:
|
55 |
try:
|
56 |
+
analysis = self.analyze_image_feature(image, feature)
|
57 |
results.append({
|
58 |
"feature": feature,
|
59 |
"analysis": analysis
|
|
|
95 |
outputs=gr.Textbox(label="Resultados da Análise", lines=20),
|
96 |
title="Analisador de Iridologia com IA",
|
97 |
description="""
|
98 |
+
Este sistema analisa imagens de íris usando IA para identificar padrões relevantes para iridologia.
|
99 |
Faça o upload de uma imagem clara do olho para análise.
|
100 |
|
101 |
Recomendações para melhores resultados:
|
|
|
112 |
|
113 |
if __name__ == "__main__":
|
114 |
iface = create_gradio_interface()
|
115 |
+
iface.launch()
|