Spaces:
Running
Running
Commit
•
6304c23
1
Parent(s):
71a4113
Subindo arquivos3
Browse files
app.py
CHANGED
@@ -7,21 +7,23 @@ 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",
|
14 |
-
"TeachableMachineImageClassifier*", "SpeechRecognizer*", "FaceExtension*",
|
15 |
]
|
16 |
|
17 |
# Padrões para cada categoria
|
18 |
drawing_and_animation_patterns = ["Ball", "Canvas", "ImageSprite"]
|
19 |
-
maps_patterns = ["Map", "Marker", "Circle", "FeatureCollection", "LineString", "Navigation",
|
20 |
-
sensors_patterns = ["AccelerometerSensor", "BarcodeScanner", "Barometer", "Clock", "GyroscopeSensor", "Hygrometer", "LightSensor", "LocationSensor", "MagneticFieldSensor", "NearField",
|
21 |
social_patterns = ["ContactPicker", "EmailPicker", "PhoneCall", "PhoneNumberPicker", "Texting", "Twitter"]
|
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:
|
@@ -110,9 +114,12 @@ def extract_project_info_from_properties(file_path):
|
|
110 |
|
111 |
# Complementary method for extracting the app name from .scm files
|
112 |
if app_name == "N/A":
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
116 |
|
117 |
return {
|
118 |
'timestamp': timestamp,
|
@@ -121,6 +128,10 @@ def extract_project_info_from_properties(file_path):
|
|
121 |
'authURL': authURL
|
122 |
}
|
123 |
|
|
|
|
|
|
|
|
|
124 |
def extract_ai_components(components):
|
125 |
ai_components = []
|
126 |
for component in components:
|
@@ -142,29 +153,35 @@ def extract_media_files(file_path: str):
|
|
142 |
return media_files
|
143 |
|
144 |
def list_components_in_aia_file(file_path):
|
|
|
145 |
results_df = pd.DataFrame(columns=[
|
146 |
'aia_file', 'project_info', 'components', 'IA components', 'screens', 'operators',
|
147 |
'variables', 'events', 'extensions', 'Media',
|
148 |
'Drawing and Animation', 'Maps', 'Sensors', 'Social', 'Storage', 'Connectivity'])
|
149 |
|
|
|
150 |
pd.set_option('display.max_colwidth', None)
|
151 |
file_name = os.path.basename(file_path)
|
|
|
152 |
|
153 |
components_list = []
|
154 |
number_of_screens = 0
|
155 |
operators_count = 0
|
156 |
variables_count = 0
|
157 |
-
events_count = 0
|
|
|
158 |
media_files = extract_media_files(file_path)
|
159 |
media_summary = ', '.join(media_files)
|
|
|
160 |
project_info = extract_project_info_from_properties(file_path)
|
161 |
project_info_str = f"Timestamp: {project_info['timestamp']}, App Name: {project_info['app_name']}, Version: {project_info['app_version']}, AuthURL: {project_info['authURL']}"
|
162 |
|
|
|
163 |
with tempfile.TemporaryDirectory() as temp_dir:
|
164 |
with ZipFile(file_path, 'r') as zip_ref:
|
165 |
zip_ref.extractall(temp_dir)
|
166 |
scm_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.scm')
|
167 |
-
bky_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.bky')
|
168 |
|
169 |
number_of_screens = len(scm_files)
|
170 |
for scm_file in scm_files:
|
@@ -175,6 +192,7 @@ def list_components_in_aia_file(file_path):
|
|
175 |
operators_count += len(re.findall(r'[+\-*/<>!=&|]', content))
|
176 |
variables_count += len(re.findall(r'"\$Name":"(.*?)"', content))
|
177 |
|
|
|
178 |
drawing_and_animation_summary = ', '.join(extract_category_components(components_list, drawing_and_animation_patterns))
|
179 |
maps_summary = ', '.join(extract_category_components(components_list, maps_patterns))
|
180 |
sensors_summary = ', '.join(extract_category_components(components_list, sensors_patterns))
|
@@ -182,59 +200,71 @@ def list_components_in_aia_file(file_path):
|
|
182 |
storage_summary = ', '.join(extract_category_components(components_list, storage_patterns))
|
183 |
connectivity_summary = ', '.join(extract_category_components(components_list, connectivity_patterns))
|
184 |
|
|
|
|
|
|
|
|
|
185 |
extensions_list = extract_extensions_from_aia(file_path)
|
186 |
|
187 |
for bky_file in bky_files:
|
188 |
with open(bky_file, 'r', encoding='utf-8', errors='ignore') as file:
|
189 |
bky_content = file.read()
|
190 |
events_count += count_events_in_bky_file(bky_content)
|
|
|
191 |
|
|
|
|
|
192 |
extensions_summary = ', '.join(list(set(extensions_list)))
|
193 |
|
194 |
components_count = collections.Counter(components_list)
|
195 |
components_summary = [f'{comp} ({count} x)' if count > 1 else comp for comp, count in components_count.items()]
|
196 |
ai_components_summary = extract_ai_components(components_list)
|
197 |
new_row = pd.DataFrame([{
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
}])
|
215 |
|
|
|
216 |
results_df = pd.concat([results_df, new_row], ignore_index=True)
|
217 |
return results_df
|
|
|
218 |
|
|
|
|
|
219 |
output_style = """
|
220 |
<style>
|
221 |
.output-container {
|
222 |
-
max-height: 500px;
|
223 |
-
overflow: auto;
|
224 |
-
display: block;
|
225 |
}
|
226 |
.output-container table {
|
227 |
-
width: 100%;
|
228 |
border-collapse: collapse;
|
229 |
}
|
230 |
.output-container th, .output-container td {
|
231 |
-
border: 1px solid #ddd;
|
232 |
text-align: left;
|
233 |
padding: 8px;
|
234 |
}
|
235 |
</style>
|
236 |
"""
|
237 |
|
|
|
238 |
def analyze_aia(uploaded_files):
|
239 |
all_results = []
|
240 |
for uploaded_file in uploaded_files:
|
@@ -253,19 +283,22 @@ def analyze_aia(uploaded_files):
|
|
253 |
except Exception as e:
|
254 |
all_results.append(f"Erro ao processar o arquivo {file_path}: {str(e)}")
|
255 |
|
|
|
256 |
combined_results_df = pd.concat(all_results, ignore_index=True)
|
257 |
html_result = combined_results_df.to_html(escape=False, classes="output-html")
|
258 |
return output_style + f'<div class="output-container">{html_result}</div>'
|
259 |
|
260 |
iface = gr.Interface(
|
261 |
fn=analyze_aia,
|
262 |
-
inputs=gr.Files(label="Upload .aia Files"),
|
263 |
outputs=gr.HTML(),
|
264 |
-
examples=[["example1.aia"]], # Certifique-se de que o caminho está correto e no formato esperado
|
265 |
title="AIA-Scope",
|
266 |
-
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.
|
267 |
live=False
|
268 |
)
|
269 |
|
270 |
if __name__ == "__main__":
|
271 |
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 |
|
18 |
# Padrões para cada categoria
|
19 |
drawing_and_animation_patterns = ["Ball", "Canvas", "ImageSprite"]
|
20 |
+
maps_patterns = ["Map", "Marker", "Circle", "FeatureCollection", "LineString", "Navigation","Polygon", "Retangle" ]
|
21 |
+
sensors_patterns = ["AccelerometerSensor", "BarcodeScanner", "Barometer", "Clock", "GyroscopeSensor", "Hygrometer", "LightSensor", "LocationSensor", "MagneticFieldSensor", "NearField","OrientationSensor", "ProximitySensor","Thermometer", "Pedometer"]
|
22 |
social_patterns = ["ContactPicker", "EmailPicker", "PhoneCall", "PhoneNumberPicker", "Texting", "Twitter"]
|
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:
|
|
|
114 |
|
115 |
# Complementary method for extracting the app name from .scm files
|
116 |
if app_name == "N/A":
|
117 |
+
print("O campo App Name não foi encontrado em project.properties. Tentando encontrar em arquivos .scm...")
|
118 |
+
app_name = extract_app_name_from_scm_files(temp_dir)
|
119 |
+
print(f"Nome do App encontrado nos arquivos .scm: {app_name}")
|
120 |
+
|
121 |
+
# ...
|
122 |
+
|
123 |
|
124 |
return {
|
125 |
'timestamp': timestamp,
|
|
|
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
|
298 |
)
|
299 |
|
300 |
if __name__ == "__main__":
|
301 |
iface.launch(debug=True)
|
302 |
+
|
303 |
+
|
304 |
+
|