Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,9 +3,7 @@ from transformers import (
|
|
3 |
AutoProcessor,
|
4 |
AutoModelForVision2Seq,
|
5 |
BlipProcessor,
|
6 |
-
BlipForQuestionAnswering
|
7 |
-
OFATokenizer,
|
8 |
-
OFAModel
|
9 |
)
|
10 |
from PIL import Image
|
11 |
import torch
|
@@ -25,10 +23,6 @@ class IridologyAnalyzer:
|
|
25 |
self.blip_processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
|
26 |
self.blip_model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
|
27 |
|
28 |
-
# OFA model
|
29 |
-
self.ofa_tokenizer = OFATokenizer.from_pretrained("OFA-Sys/ofa-base")
|
30 |
-
self.ofa_model = OFAModel.from_pretrained("OFA-Sys/ofa-base")
|
31 |
-
|
32 |
# Perguntas predefinidas para análise de iridologia
|
33 |
self.iridology_questions = [
|
34 |
"What is the color pattern of the iris?",
|
@@ -38,7 +32,11 @@ class IridologyAnalyzer:
|
|
38 |
"What is the condition of the pupil?",
|
39 |
"Are there any lines radiating from the pupil?",
|
40 |
"Is there any discoloration in specific areas?",
|
41 |
-
"What is the overall clarity of the iris?"
|
|
|
|
|
|
|
|
|
42 |
]
|
43 |
|
44 |
print("Modelos carregados com sucesso!")
|
@@ -58,42 +56,31 @@ class IridologyAnalyzer:
|
|
58 |
outputs = self.blip_model.generate(**inputs)
|
59 |
return self.blip_processor.decode(outputs[0], skip_special_tokens=True)
|
60 |
|
61 |
-
def analyze_with_ofa(self, image, question):
|
62 |
-
inputs = self.ofa_tokenizer([question], return_tensors="pt")
|
63 |
-
img = self.ofa_tokenizer(images=image, return_tensors="pt").pixel_values
|
64 |
-
|
65 |
-
outputs = self.ofa_model.generate(
|
66 |
-
input_ids=inputs.input_ids,
|
67 |
-
pixel_values=img,
|
68 |
-
max_length=50,
|
69 |
-
num_beams=4
|
70 |
-
)
|
71 |
-
return self.ofa_tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
72 |
-
|
73 |
def comprehensive_analysis(self, image):
|
74 |
"""Realiza uma análise completa usando todos os modelos e questões predefinidas."""
|
75 |
results = []
|
76 |
|
77 |
for question in self.iridology_questions:
|
78 |
# Análise com cada modelo
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
89 |
|
90 |
# Formatar resultados
|
91 |
formatted_results = "Análise Detalhada de Iridologia:\n\n"
|
92 |
for result in results:
|
93 |
formatted_results += f"Pergunta: {result['question']}\n"
|
94 |
-
formatted_results += f"GIT: {result['git_analysis']}\n"
|
95 |
-
formatted_results += f"BLIP: {result['blip_analysis']}\n"
|
96 |
-
formatted_results += f"OFA: {result['ofa_analysis']}\n"
|
97 |
formatted_results += "-" * 50 + "\n"
|
98 |
|
99 |
return formatted_results
|
@@ -124,6 +111,12 @@ def create_gradio_interface():
|
|
124 |
description="""
|
125 |
Este sistema analisa imagens de íris usando múltiplos modelos de IA para identificar padrões relevantes para iridologia.
|
126 |
Faça o upload de uma imagem clara do olho para análise.
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
""",
|
128 |
examples=[],
|
129 |
cache_examples=True
|
@@ -133,4 +126,4 @@ def create_gradio_interface():
|
|
133 |
|
134 |
if __name__ == "__main__":
|
135 |
iface = create_gradio_interface()
|
136 |
-
iface.launch(
|
|
|
3 |
AutoProcessor,
|
4 |
AutoModelForVision2Seq,
|
5 |
BlipProcessor,
|
6 |
+
BlipForQuestionAnswering
|
|
|
|
|
7 |
)
|
8 |
from PIL import Image
|
9 |
import torch
|
|
|
23 |
self.blip_processor = BlipProcessor.from_pretrained("Salesforce/blip-vqa-base")
|
24 |
self.blip_model = BlipForQuestionAnswering.from_pretrained("Salesforce/blip-vqa-base")
|
25 |
|
|
|
|
|
|
|
|
|
26 |
# Perguntas predefinidas para análise de iridologia
|
27 |
self.iridology_questions = [
|
28 |
"What is the color pattern of the iris?",
|
|
|
32 |
"What is the condition of the pupil?",
|
33 |
"Are there any lines radiating from the pupil?",
|
34 |
"Is there any discoloration in specific areas?",
|
35 |
+
"What is the overall clarity of the iris?",
|
36 |
+
"Describe any notable features in the iris tissue",
|
37 |
+
"Are there any white marks or spots?",
|
38 |
+
"Describe the structure of the iris fibers",
|
39 |
+
"What is the condition of the iris border?"
|
40 |
]
|
41 |
|
42 |
print("Modelos carregados com sucesso!")
|
|
|
56 |
outputs = self.blip_model.generate(**inputs)
|
57 |
return self.blip_processor.decode(outputs[0], skip_special_tokens=True)
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
def comprehensive_analysis(self, image):
|
60 |
"""Realiza uma análise completa usando todos os modelos e questões predefinidas."""
|
61 |
results = []
|
62 |
|
63 |
for question in self.iridology_questions:
|
64 |
# Análise com cada modelo
|
65 |
+
try:
|
66 |
+
git_result = self.analyze_with_git(image, question)
|
67 |
+
blip_result = self.analyze_with_blip(image, question)
|
68 |
+
|
69 |
+
results.append({
|
70 |
+
"question": question,
|
71 |
+
"git_analysis": git_result,
|
72 |
+
"blip_analysis": blip_result
|
73 |
+
})
|
74 |
+
except Exception as e:
|
75 |
+
print(f"Erro ao processar questão '{question}': {str(e)}")
|
76 |
+
continue
|
77 |
|
78 |
# Formatar resultados
|
79 |
formatted_results = "Análise Detalhada de Iridologia:\n\n"
|
80 |
for result in results:
|
81 |
formatted_results += f"Pergunta: {result['question']}\n"
|
82 |
+
formatted_results += f"Análise 1 (GIT): {result['git_analysis']}\n"
|
83 |
+
formatted_results += f"Análise 2 (BLIP): {result['blip_analysis']}\n"
|
|
|
84 |
formatted_results += "-" * 50 + "\n"
|
85 |
|
86 |
return formatted_results
|
|
|
111 |
description="""
|
112 |
Este sistema analisa imagens de íris usando múltiplos modelos de IA para identificar padrões relevantes para iridologia.
|
113 |
Faça o upload de uma imagem clara do olho para análise.
|
114 |
+
|
115 |
+
Recomendações para melhores resultados:
|
116 |
+
1. Use imagens bem iluminadas
|
117 |
+
2. Garanta que a íris esteja em foco
|
118 |
+
3. Evite reflexos excessivos
|
119 |
+
4. Enquadre apenas o olho na imagem
|
120 |
""",
|
121 |
examples=[],
|
122 |
cache_examples=True
|
|
|
126 |
|
127 |
if __name__ == "__main__":
|
128 |
iface = create_gradio_interface()
|
129 |
+
iface.launch()
|