Spaces:
Sleeping
Sleeping
Commit
·
71b15c5
1
Parent(s):
085c70b
Subindo arquivos1112
Browse files
app.py
CHANGED
@@ -7,10 +7,11 @@ import pandas as pd
|
|
7 |
import collections
|
8 |
import json
|
9 |
import glob
|
|
|
10 |
|
11 |
-
# Padrões de IA
|
12 |
ai_patterns = [
|
13 |
-
"PIC*", "PersonalImageClassifier*", "Look*", "LookExtension*", "ChatBot", "ImageBot", "TMIC","Gemini*",
|
14 |
"TeachableMachineImageClassifier*", "SpeechRecognizer*", "FaceExtension*","Pose*","Posenet","PosenetExtension", "Eliza*", "Alexa*"
|
15 |
]
|
16 |
|
@@ -22,6 +23,7 @@ social_patterns = ["ContactPicker", "EmailPicker", "PhoneCall", "PhoneNumberPick
|
|
22 |
storage_patterns = ["File", "CloudDB", "DataFile", "Spreadsheet", "FusiontablesControl", "TinyDB", "TinyWebDB"]
|
23 |
connectivity_patterns = ["BluetoothClient", "ActivityStarter", "Serial", "BluetoothServer", "Web"]
|
24 |
|
|
|
25 |
def extract_components_using_regex(scm_content):
|
26 |
pattern = r'"\$Type":"(.*?)"'
|
27 |
components = re.findall(pattern, scm_content)
|
@@ -29,6 +31,7 @@ def extract_components_using_regex(scm_content):
|
|
29 |
components.append("Using Roboflow")
|
30 |
return components
|
31 |
|
|
|
32 |
def extract_category_components(components, patterns):
|
33 |
category_components = []
|
34 |
for component in components:
|
@@ -37,6 +40,7 @@ def extract_category_components(components, patterns):
|
|
37 |
category_components.append(component)
|
38 |
return category_components
|
39 |
|
|
|
40 |
def extract_extensions_from_aia(file_path: str):
|
41 |
extensions = []
|
42 |
with ZipFile(file_path, 'r') as zip_ref:
|
@@ -124,6 +128,10 @@ def extract_project_info_from_properties(file_path):
|
|
124 |
'authURL': authURL
|
125 |
}
|
126 |
|
|
|
|
|
|
|
|
|
127 |
def extract_ai_components(components):
|
128 |
ai_components = []
|
129 |
for component in components:
|
@@ -145,29 +153,35 @@ def extract_media_files(file_path: str):
|
|
145 |
return media_files
|
146 |
|
147 |
def list_components_in_aia_file(file_path):
|
|
|
148 |
results_df = pd.DataFrame(columns=[
|
149 |
'aia_file', 'project_info', 'components', 'IA components', 'screens', 'operators',
|
150 |
'variables', 'events', 'extensions', 'Media',
|
151 |
'Drawing and Animation', 'Maps', 'Sensors', 'Social', 'Storage', 'Connectivity'])
|
152 |
|
|
|
153 |
pd.set_option('display.max_colwidth', None)
|
154 |
file_name = os.path.basename(file_path)
|
|
|
155 |
|
156 |
components_list = []
|
157 |
number_of_screens = 0
|
158 |
operators_count = 0
|
159 |
variables_count = 0
|
160 |
-
events_count = 0
|
|
|
161 |
media_files = extract_media_files(file_path)
|
162 |
media_summary = ', '.join(media_files)
|
|
|
163 |
project_info = extract_project_info_from_properties(file_path)
|
164 |
project_info_str = f"Timestamp: {project_info['timestamp']}, App Name: {project_info['app_name']}, Version: {project_info['app_version']}, AuthURL: {project_info['authURL']}"
|
165 |
|
|
|
166 |
with tempfile.TemporaryDirectory() as temp_dir:
|
167 |
with ZipFile(file_path, 'r') as zip_ref:
|
168 |
zip_ref.extractall(temp_dir)
|
169 |
scm_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.scm')
|
170 |
-
bky_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.bky')
|
171 |
|
172 |
number_of_screens = len(scm_files)
|
173 |
for scm_file in scm_files:
|
@@ -178,6 +192,7 @@ def list_components_in_aia_file(file_path):
|
|
178 |
operators_count += len(re.findall(r'[+\-*/<>!=&|]', content))
|
179 |
variables_count += len(re.findall(r'"\$Name":"(.*?)"', content))
|
180 |
|
|
|
181 |
drawing_and_animation_summary = ', '.join(extract_category_components(components_list, drawing_and_animation_patterns))
|
182 |
maps_summary = ', '.join(extract_category_components(components_list, maps_patterns))
|
183 |
sensors_summary = ', '.join(extract_category_components(components_list, sensors_patterns))
|
@@ -185,59 +200,71 @@ def list_components_in_aia_file(file_path):
|
|
185 |
storage_summary = ', '.join(extract_category_components(components_list, storage_patterns))
|
186 |
connectivity_summary = ', '.join(extract_category_components(components_list, connectivity_patterns))
|
187 |
|
|
|
|
|
|
|
|
|
188 |
extensions_list = extract_extensions_from_aia(file_path)
|
189 |
|
190 |
for bky_file in bky_files:
|
191 |
with open(bky_file, 'r', encoding='utf-8', errors='ignore') as file:
|
192 |
bky_content = file.read()
|
193 |
events_count += count_events_in_bky_file(bky_content)
|
|
|
|
|
194 |
|
|
|
195 |
extensions_summary = ', '.join(list(set(extensions_list)))
|
196 |
|
197 |
components_count = collections.Counter(components_list)
|
198 |
components_summary = [f'{comp} ({count} x)' if count > 1 else comp for comp, count in components_count.items()]
|
199 |
ai_components_summary = extract_ai_components(components_list)
|
200 |
new_row = pd.DataFrame([{
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
}])
|
218 |
|
|
|
219 |
results_df = pd.concat([results_df, new_row], ignore_index=True)
|
220 |
return results_df
|
|
|
221 |
|
|
|
|
|
222 |
output_style = """
|
223 |
<style>
|
224 |
.output-container {
|
225 |
-
max-height: 500px;
|
226 |
-
overflow: auto;
|
227 |
-
display: block;
|
228 |
}
|
229 |
.output-container table {
|
230 |
-
width: 100%;
|
231 |
border-collapse: collapse;
|
232 |
}
|
233 |
.output-container th, .output-container td {
|
234 |
-
border: 1px solid #ddd;
|
235 |
text-align: left;
|
236 |
padding: 8px;
|
237 |
}
|
238 |
</style>
|
239 |
"""
|
240 |
|
|
|
241 |
def analyze_aia(uploaded_files):
|
242 |
all_results = []
|
243 |
for uploaded_file in uploaded_files:
|
@@ -256,28 +283,15 @@ def analyze_aia(uploaded_files):
|
|
256 |
except Exception as e:
|
257 |
all_results.append(f"Erro ao processar o arquivo {file_path}: {str(e)}")
|
258 |
|
|
|
259 |
combined_results_df = pd.concat(all_results, ignore_index=True)
|
260 |
html_result = combined_results_df.to_html(escape=False, classes="output-html")
|
261 |
return output_style + f'<div class="output-container">{html_result}</div>'
|
262 |
|
263 |
-
# Listar arquivos no diretório /mnt/data
|
264 |
-
print("Arquivos no diretório /mnt/data:")
|
265 |
-
for root, dirs, files in os.walk("/mnt/data"):
|
266 |
-
for file in files:
|
267 |
-
print(os.path.join(root, file))
|
268 |
-
|
269 |
-
# Caminho do exemplo fornecido
|
270 |
-
example_file_path = "/mnt/data/example1.aia"
|
271 |
-
|
272 |
-
# Verifique se o arquivo existe
|
273 |
-
if not os.path.exists(example_file_path):
|
274 |
-
raise FileNotFoundError(f"O arquivo de exemplo {example_file_path} não foi encontrado.")
|
275 |
-
|
276 |
iface = gr.Interface(
|
277 |
fn=analyze_aia,
|
278 |
-
inputs=gr.Files(label="Upload .aia Files"),
|
279 |
outputs=gr.HTML(),
|
280 |
-
examples=[[example_file_path]], # Use o caminho absoluto fornecido
|
281 |
title="AIA-Scope",
|
282 |
description="Upload .aia (or multiples .aia) files to analyze/dissect their components. An .aia file from MIT App Inventor is a project file format that contains all the necessary information for an App Inventor project.",
|
283 |
live=False
|
@@ -285,3 +299,6 @@ iface = gr.Interface(
|
|
285 |
|
286 |
if __name__ == "__main__":
|
287 |
iface.launch(debug=True)
|
|
|
|
|
|
|
|
7 |
import collections
|
8 |
import json
|
9 |
import glob
|
10 |
+
from io import BytesIO
|
11 |
|
12 |
+
# Padrões de IA
|
13 |
ai_patterns = [
|
14 |
+
"PIC*", "PersonalImageClassifier*", "Look*", "LookExtension*", "ChatBot", "ImageBot", "TMIC","Gemini*","Llama*","TeachableMachine*",
|
15 |
"TeachableMachineImageClassifier*", "SpeechRecognizer*", "FaceExtension*","Pose*","Posenet","PosenetExtension", "Eliza*", "Alexa*"
|
16 |
]
|
17 |
|
|
|
23 |
storage_patterns = ["File", "CloudDB", "DataFile", "Spreadsheet", "FusiontablesControl", "TinyDB", "TinyWebDB"]
|
24 |
connectivity_patterns = ["BluetoothClient", "ActivityStarter", "Serial", "BluetoothServer", "Web"]
|
25 |
|
26 |
+
|
27 |
def extract_components_using_regex(scm_content):
|
28 |
pattern = r'"\$Type":"(.*?)"'
|
29 |
components = re.findall(pattern, scm_content)
|
|
|
31 |
components.append("Using Roboflow")
|
32 |
return components
|
33 |
|
34 |
+
|
35 |
def extract_category_components(components, patterns):
|
36 |
category_components = []
|
37 |
for component in components:
|
|
|
40 |
category_components.append(component)
|
41 |
return category_components
|
42 |
|
43 |
+
|
44 |
def extract_extensions_from_aia(file_path: str):
|
45 |
extensions = []
|
46 |
with ZipFile(file_path, 'r') as zip_ref:
|
|
|
128 |
'authURL': authURL
|
129 |
}
|
130 |
|
131 |
+
|
132 |
+
|
133 |
+
|
134 |
+
|
135 |
def extract_ai_components(components):
|
136 |
ai_components = []
|
137 |
for component in components:
|
|
|
153 |
return media_files
|
154 |
|
155 |
def list_components_in_aia_file(file_path):
|
156 |
+
#
|
157 |
results_df = pd.DataFrame(columns=[
|
158 |
'aia_file', 'project_info', 'components', 'IA components', 'screens', 'operators',
|
159 |
'variables', 'events', 'extensions', 'Media',
|
160 |
'Drawing and Animation', 'Maps', 'Sensors', 'Social', 'Storage', 'Connectivity'])
|
161 |
|
162 |
+
|
163 |
pd.set_option('display.max_colwidth', None)
|
164 |
file_name = os.path.basename(file_path)
|
165 |
+
#
|
166 |
|
167 |
components_list = []
|
168 |
number_of_screens = 0
|
169 |
operators_count = 0
|
170 |
variables_count = 0
|
171 |
+
events_count = 0 #
|
172 |
+
#
|
173 |
media_files = extract_media_files(file_path)
|
174 |
media_summary = ', '.join(media_files)
|
175 |
+
#
|
176 |
project_info = extract_project_info_from_properties(file_path)
|
177 |
project_info_str = f"Timestamp: {project_info['timestamp']}, App Name: {project_info['app_name']}, Version: {project_info['app_version']}, AuthURL: {project_info['authURL']}"
|
178 |
|
179 |
+
|
180 |
with tempfile.TemporaryDirectory() as temp_dir:
|
181 |
with ZipFile(file_path, 'r') as zip_ref:
|
182 |
zip_ref.extractall(temp_dir)
|
183 |
scm_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.scm')
|
184 |
+
bky_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.bky') # Esta linha define bky_files
|
185 |
|
186 |
number_of_screens = len(scm_files)
|
187 |
for scm_file in scm_files:
|
|
|
192 |
operators_count += len(re.findall(r'[+\-*/<>!=&|]', content))
|
193 |
variables_count += len(re.findall(r'"\$Name":"(.*?)"', content))
|
194 |
|
195 |
+
#
|
196 |
drawing_and_animation_summary = ', '.join(extract_category_components(components_list, drawing_and_animation_patterns))
|
197 |
maps_summary = ', '.join(extract_category_components(components_list, maps_patterns))
|
198 |
sensors_summary = ', '.join(extract_category_components(components_list, sensors_patterns))
|
|
|
200 |
storage_summary = ', '.join(extract_category_components(components_list, storage_patterns))
|
201 |
connectivity_summary = ', '.join(extract_category_components(components_list, connectivity_patterns))
|
202 |
|
203 |
+
|
204 |
+
#
|
205 |
+
#
|
206 |
+
extensions_list = []
|
207 |
extensions_list = extract_extensions_from_aia(file_path)
|
208 |
|
209 |
for bky_file in bky_files:
|
210 |
with open(bky_file, 'r', encoding='utf-8', errors='ignore') as file:
|
211 |
bky_content = file.read()
|
212 |
events_count += count_events_in_bky_file(bky_content)
|
213 |
+
#
|
214 |
+
|
215 |
|
216 |
+
#
|
217 |
extensions_summary = ', '.join(list(set(extensions_list)))
|
218 |
|
219 |
components_count = collections.Counter(components_list)
|
220 |
components_summary = [f'{comp} ({count} x)' if count > 1 else comp for comp, count in components_count.items()]
|
221 |
ai_components_summary = extract_ai_components(components_list)
|
222 |
new_row = pd.DataFrame([{
|
223 |
+
'aia_file': file_name,
|
224 |
+
'project_info': project_info_str,
|
225 |
+
'components': ', '.join(components_summary),
|
226 |
+
'IA components': ', '.join(ai_components_summary),
|
227 |
+
'screens': number_of_screens,
|
228 |
+
'operators': operators_count,
|
229 |
+
'variables': variables_count,
|
230 |
+
'events': events_count,
|
231 |
+
'extensions': extensions_summary,
|
232 |
+
'Media': media_summary,
|
233 |
+
'Drawing and Animation': drawing_and_animation_summary,
|
234 |
+
'Maps': maps_summary,
|
235 |
+
'Sensors': sensors_summary,
|
236 |
+
'Social': social_summary,
|
237 |
+
'Storage': storage_summary,
|
238 |
+
'Connectivity': connectivity_summary
|
239 |
}])
|
240 |
|
241 |
+
#
|
242 |
results_df = pd.concat([results_df, new_row], ignore_index=True)
|
243 |
return results_df
|
244 |
+
#
|
245 |
|
246 |
+
#
|
247 |
+
#
|
248 |
output_style = """
|
249 |
<style>
|
250 |
.output-container {
|
251 |
+
max-height: 500px; /* a */
|
252 |
+
overflow: auto; /* a */
|
253 |
+
display: block; /* a */
|
254 |
}
|
255 |
.output-container table {
|
256 |
+
width: 100%; /* a */
|
257 |
border-collapse: collapse;
|
258 |
}
|
259 |
.output-container th, .output-container td {
|
260 |
+
border: 1px solid #ddd; /* a */
|
261 |
text-align: left;
|
262 |
padding: 8px;
|
263 |
}
|
264 |
</style>
|
265 |
"""
|
266 |
|
267 |
+
#
|
268 |
def analyze_aia(uploaded_files):
|
269 |
all_results = []
|
270 |
for uploaded_file in uploaded_files:
|
|
|
283 |
except Exception as e:
|
284 |
all_results.append(f"Erro ao processar o arquivo {file_path}: {str(e)}")
|
285 |
|
286 |
+
#
|
287 |
combined_results_df = pd.concat(all_results, ignore_index=True)
|
288 |
html_result = combined_results_df.to_html(escape=False, classes="output-html")
|
289 |
return output_style + f'<div class="output-container">{html_result}</div>'
|
290 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
iface = gr.Interface(
|
292 |
fn=analyze_aia,
|
293 |
+
inputs=gr.Files(label="Upload .aia Files"), #
|
294 |
outputs=gr.HTML(),
|
|
|
295 |
title="AIA-Scope",
|
296 |
description="Upload .aia (or multiples .aia) files to analyze/dissect their components. An .aia file from MIT App Inventor is a project file format that contains all the necessary information for an App Inventor project.",
|
297 |
live=False
|
|
|
299 |
|
300 |
if __name__ == "__main__":
|
301 |
iface.launch(debug=True)
|
302 |
+
|
303 |
+
|
304 |
+
|