Spaces:
Sleeping
Sleeping
Commit
·
8f945c7
1
Parent(s):
71b15c5
Subindo arquivos333
Browse files- app.py +21 -51
- example1.aia → example2.aia +0 -0
app.py
CHANGED
@@ -23,7 +23,6 @@ social_patterns = ["ContactPicker", "EmailPicker", "PhoneCall", "PhoneNumberPick
|
|
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,7 +30,6 @@ def extract_components_using_regex(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,7 +38,6 @@ def extract_category_components(components, patterns):
|
|
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:
|
@@ -118,9 +115,6 @@ def extract_project_info_from_properties(file_path):
|
|
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,
|
126 |
'app_name': app_name,
|
@@ -128,10 +122,6 @@ def extract_project_info_from_properties(file_path):
|
|
128 |
'authURL': authURL
|
129 |
}
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
def extract_ai_components(components):
|
136 |
ai_components = []
|
137 |
for component in components:
|
@@ -153,35 +143,31 @@ def extract_media_files(file_path: str):
|
|
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')
|
185 |
|
186 |
number_of_screens = len(scm_files)
|
187 |
for scm_file in scm_files:
|
@@ -192,7 +178,6 @@ def list_components_in_aia_file(file_path):
|
|
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,9 +185,6 @@ def list_components_in_aia_file(file_path):
|
|
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 |
|
@@ -210,41 +192,34 @@ def list_components_in_aia_file(file_path):
|
|
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 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
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 {
|
@@ -264,7 +239,6 @@ output_style = """
|
|
264 |
</style>
|
265 |
"""
|
266 |
|
267 |
-
#
|
268 |
def analyze_aia(uploaded_files):
|
269 |
all_results = []
|
270 |
for uploaded_file in uploaded_files:
|
@@ -283,14 +257,13 @@ def analyze_aia(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.",
|
@@ -299,6 +272,3 @@ iface = gr.Interface(
|
|
299 |
|
300 |
if __name__ == "__main__":
|
301 |
iface.launch(debug=True)
|
302 |
-
|
303 |
-
|
304 |
-
|
|
|
23 |
storage_patterns = ["File", "CloudDB", "DataFile", "Spreadsheet", "FusiontablesControl", "TinyDB", "TinyWebDB"]
|
24 |
connectivity_patterns = ["BluetoothClient", "ActivityStarter", "Serial", "BluetoothServer", "Web"]
|
25 |
|
|
|
26 |
def extract_components_using_regex(scm_content):
|
27 |
pattern = r'"\$Type":"(.*?)"'
|
28 |
components = re.findall(pattern, scm_content)
|
|
|
30 |
components.append("Using Roboflow")
|
31 |
return components
|
32 |
|
|
|
33 |
def extract_category_components(components, patterns):
|
34 |
category_components = []
|
35 |
for component in components:
|
|
|
38 |
category_components.append(component)
|
39 |
return category_components
|
40 |
|
|
|
41 |
def extract_extensions_from_aia(file_path: str):
|
42 |
extensions = []
|
43 |
with ZipFile(file_path, 'r') as zip_ref:
|
|
|
115 |
app_name = extract_app_name_from_scm_files(temp_dir)
|
116 |
print(f"Nome do App encontrado nos arquivos .scm: {app_name}")
|
117 |
|
|
|
|
|
|
|
118 |
return {
|
119 |
'timestamp': timestamp,
|
120 |
'app_name': app_name,
|
|
|
122 |
'authURL': authURL
|
123 |
}
|
124 |
|
|
|
|
|
|
|
|
|
125 |
def extract_ai_components(components):
|
126 |
ai_components = []
|
127 |
for component in components:
|
|
|
143 |
return media_files
|
144 |
|
145 |
def list_components_in_aia_file(file_path):
|
|
|
146 |
results_df = pd.DataFrame(columns=[
|
147 |
'aia_file', 'project_info', 'components', 'IA components', 'screens', 'operators',
|
148 |
'variables', 'events', 'extensions', 'Media',
|
149 |
'Drawing and Animation', 'Maps', 'Sensors', 'Social', 'Storage', 'Connectivity'])
|
150 |
|
|
|
151 |
pd.set_option('display.max_colwidth', None)
|
152 |
file_name = os.path.basename(file_path)
|
|
|
153 |
|
154 |
components_list = []
|
155 |
number_of_screens = 0
|
156 |
operators_count = 0
|
157 |
variables_count = 0
|
158 |
+
events_count = 0
|
159 |
+
|
160 |
media_files = extract_media_files(file_path)
|
161 |
media_summary = ', '.join(media_files)
|
162 |
+
|
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 |
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 |
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 = []
|
189 |
extensions_list = extract_extensions_from_aia(file_path)
|
190 |
|
|
|
192 |
with open(bky_file, 'r', encoding='utf-8', errors='ignore') as file:
|
193 |
bky_content = file.read()
|
194 |
events_count += count_events_in_bky_file(bky_content)
|
|
|
195 |
|
|
|
|
|
196 |
extensions_summary = ', '.join(list(set(extensions_list)))
|
197 |
|
198 |
components_count = collections.Counter(components_list)
|
199 |
components_summary = [f'{comp} ({count} x)' if count > 1 else comp for comp, count in components_count.items()]
|
200 |
ai_components_summary = extract_ai_components(components_list)
|
201 |
new_row = pd.DataFrame([{
|
202 |
+
'aia_file': file_name,
|
203 |
+
'project_info': project_info_str,
|
204 |
+
'components': ', '.join(components_summary),
|
205 |
+
'IA components': ', '.join(ai_components_summary),
|
206 |
+
'screens': number_of_screens,
|
207 |
+
'operators': operators_count,
|
208 |
+
'variables': variables_count,
|
209 |
+
'events': events_count,
|
210 |
+
'extensions': extensions_summary,
|
211 |
+
'Media': media_summary,
|
212 |
+
'Drawing and Animation': drawing_and_animation_summary,
|
213 |
+
'Maps': maps_summary,
|
214 |
+
'Sensors': sensors_summary,
|
215 |
+
'Social': social_summary,
|
216 |
+
'Storage': storage_summary,
|
217 |
+
'Connectivity': connectivity_summary
|
218 |
}])
|
219 |
|
|
|
220 |
results_df = pd.concat([results_df, new_row], ignore_index=True)
|
221 |
return results_df
|
|
|
222 |
|
|
|
|
|
223 |
output_style = """
|
224 |
<style>
|
225 |
.output-container {
|
|
|
239 |
</style>
|
240 |
"""
|
241 |
|
|
|
242 |
def analyze_aia(uploaded_files):
|
243 |
all_results = []
|
244 |
for uploaded_file in uploaded_files:
|
|
|
257 |
except Exception as e:
|
258 |
all_results.append(f"Erro ao processar o arquivo {file_path}: {str(e)}")
|
259 |
|
|
|
260 |
combined_results_df = pd.concat(all_results, ignore_index=True)
|
261 |
html_result = combined_results_df.to_html(escape=False, classes="output-html")
|
262 |
return output_style + f'<div class="output-container">{html_result}</div>'
|
263 |
|
264 |
iface = gr.Interface(
|
265 |
fn=analyze_aia,
|
266 |
+
inputs=gr.Files(label="Upload .aia Files"),
|
267 |
outputs=gr.HTML(),
|
268 |
title="AIA-Scope",
|
269 |
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.",
|
|
|
272 |
|
273 |
if __name__ == "__main__":
|
274 |
iface.launch(debug=True)
|
|
|
|
|
|
example1.aia → example2.aia
RENAMED
File without changes
|