Spaces:
Sleeping
Sleeping
rmayormartins
commited on
Commit
•
5405c27
1
Parent(s):
e53b39f
Subindo arquivos11121
Browse files
app.py
CHANGED
@@ -23,6 +23,7 @@ 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 |
def extract_components_using_regex(scm_content):
|
27 |
pattern = r'"\$Type":"(.*?)"'
|
28 |
components = re.findall(pattern, scm_content)
|
@@ -30,6 +31,7 @@ def extract_components_using_regex(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,6 +40,7 @@ def extract_category_components(components, patterns):
|
|
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:
|
@@ -53,6 +56,7 @@ def extract_extensions_from_aia(file_path: str):
|
|
53 |
return extensions
|
54 |
|
55 |
def count_events_in_bky_file(bky_content):
|
|
|
56 |
return bky_content.count('<block type="component_event"')
|
57 |
|
58 |
def extract_app_name_from_scm_files(temp_dir):
|
@@ -60,42 +64,63 @@ def extract_app_name_from_scm_files(temp_dir):
|
|
60 |
for scm_file in scm_files:
|
61 |
with open(scm_file, 'r', encoding='utf-8', errors='ignore') as file:
|
62 |
content = file.read()
|
|
|
|
|
63 |
regex_patterns = [
|
64 |
r'"AppName"\s*:\s*"([^"]+)"',
|
65 |
-
r'"AppName"\s*:\s*\'([^\']+)\''
|
66 |
]
|
|
|
67 |
for pattern in regex_patterns:
|
68 |
app_name_match = re.search(pattern, content)
|
69 |
if app_name_match:
|
70 |
return app_name_match.group(1)
|
|
|
|
|
71 |
print(f"Aviso: Nome do aplicativo não encontrado no diretório {temp_dir}")
|
72 |
return "N/A"
|
73 |
|
74 |
def extract_project_info_from_properties(file_path):
|
|
|
75 |
timestamp = "N/A"
|
76 |
app_name = "N/A"
|
77 |
app_version = "N/A"
|
78 |
authURL = "ai2.appinventor.mit.edu"
|
79 |
|
|
|
80 |
with tempfile.TemporaryDirectory() as temp_dir:
|
81 |
with ZipFile(file_path, 'r') as zip_ref:
|
82 |
zip_ref.extractall(temp_dir)
|
|
|
83 |
project_properties_file_path = 'youngandroidproject/project.properties'
|
|
|
|
|
84 |
if project_properties_file_path in zip_ref.namelist():
|
85 |
with zip_ref.open(project_properties_file_path) as file:
|
86 |
project_properties_lines = file.read().decode('utf-8').splitlines()
|
|
|
|
|
87 |
timestamp = project_properties_lines[1] if len(project_properties_lines) > 1 else "N/A"
|
|
|
|
|
88 |
for line in project_properties_lines:
|
89 |
app_name_match = re.match(r'aname=(.*)', line)
|
90 |
if app_name_match:
|
91 |
app_name = app_name_match.group(1)
|
|
|
92 |
app_version_match = re.match(r'versionname=(.*)', line)
|
93 |
if app_version_match:
|
94 |
app_version = app_version_match.group(1)
|
|
|
|
|
95 |
if app_name == "N/A":
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
return {
|
100 |
'timestamp': timestamp,
|
101 |
'app_name': app_name,
|
@@ -103,6 +128,10 @@ def extract_project_info_from_properties(file_path):
|
|
103 |
'authURL': authURL
|
104 |
}
|
105 |
|
|
|
|
|
|
|
|
|
106 |
def extract_ai_components(components):
|
107 |
ai_components = []
|
108 |
for component in components:
|
@@ -124,31 +153,35 @@ def extract_media_files(file_path: str):
|
|
124 |
return media_files
|
125 |
|
126 |
def list_components_in_aia_file(file_path):
|
|
|
127 |
results_df = pd.DataFrame(columns=[
|
128 |
'aia_file', 'project_info', 'components', 'IA components', 'screens', 'operators',
|
129 |
'variables', 'events', 'extensions', 'Media',
|
130 |
'Drawing and Animation', 'Maps', 'Sensors', 'Social', 'Storage', 'Connectivity'])
|
131 |
|
|
|
132 |
pd.set_option('display.max_colwidth', None)
|
133 |
file_name = os.path.basename(file_path)
|
|
|
134 |
|
135 |
components_list = []
|
136 |
number_of_screens = 0
|
137 |
operators_count = 0
|
138 |
variables_count = 0
|
139 |
-
events_count = 0
|
140 |
-
|
141 |
media_files = extract_media_files(file_path)
|
142 |
media_summary = ', '.join(media_files)
|
143 |
-
|
144 |
project_info = extract_project_info_from_properties(file_path)
|
145 |
project_info_str = f"Timestamp: {project_info['timestamp']}, App Name: {project_info['app_name']}, Version: {project_info['app_version']}, AuthURL: {project_info['authURL']}"
|
146 |
|
|
|
147 |
with tempfile.TemporaryDirectory() as temp_dir:
|
148 |
with ZipFile(file_path, 'r') as zip_ref:
|
149 |
zip_ref.extractall(temp_dir)
|
150 |
scm_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.scm')
|
151 |
-
bky_files = glob.glob(temp_dir + '/src/appinventor/*/*/*.bky')
|
152 |
|
153 |
number_of_screens = len(scm_files)
|
154 |
for scm_file in scm_files:
|
@@ -159,6 +192,7 @@ def list_components_in_aia_file(file_path):
|
|
159 |
operators_count += len(re.findall(r'[+\-*/<>!=&|]', content))
|
160 |
variables_count += len(re.findall(r'"\$Name":"(.*?)"', content))
|
161 |
|
|
|
162 |
drawing_and_animation_summary = ', '.join(extract_category_components(components_list, drawing_and_animation_patterns))
|
163 |
maps_summary = ', '.join(extract_category_components(components_list, maps_patterns))
|
164 |
sensors_summary = ', '.join(extract_category_components(components_list, sensors_patterns))
|
@@ -166,58 +200,71 @@ def list_components_in_aia_file(file_path):
|
|
166 |
storage_summary = ', '.join(extract_category_components(components_list, storage_patterns))
|
167 |
connectivity_summary = ', '.join(extract_category_components(components_list, connectivity_patterns))
|
168 |
|
|
|
|
|
|
|
|
|
169 |
extensions_list = extract_extensions_from_aia(file_path)
|
170 |
|
171 |
for bky_file in bky_files:
|
172 |
with open(bky_file, 'r', encoding='utf-8', errors='ignore') as file:
|
173 |
bky_content = file.read()
|
174 |
events_count += count_events_in_bky_file(bky_content)
|
|
|
|
|
175 |
|
|
|
176 |
extensions_summary = ', '.join(list(set(extensions_list)))
|
177 |
|
178 |
components_count = collections.Counter(components_list)
|
179 |
components_summary = [f'{comp} ({count} x)' if count > 1 else comp for comp, count in components_count.items()]
|
180 |
ai_components_summary = extract_ai_components(components_list)
|
181 |
new_row = pd.DataFrame([{
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
}])
|
|
|
|
|
199 |
results_df = pd.concat([results_df, new_row], ignore_index=True)
|
200 |
return results_df
|
|
|
201 |
|
|
|
|
|
202 |
output_style = """
|
203 |
<style>
|
204 |
.output-container {
|
205 |
-
max-height: 500px;
|
206 |
-
overflow: auto;
|
207 |
-
display: block;
|
208 |
}
|
209 |
.output-container table {
|
210 |
-
width: 100%;
|
211 |
border-collapse: collapse;
|
212 |
}
|
213 |
.output-container th, .output-container td {
|
214 |
-
border: 1px solid #ddd;
|
215 |
text-align: left;
|
216 |
padding: 8px;
|
217 |
}
|
218 |
</style>
|
219 |
"""
|
220 |
|
|
|
221 |
def analyze_aia(uploaded_files):
|
222 |
all_results = []
|
223 |
for uploaded_file in uploaded_files:
|
@@ -235,19 +282,23 @@ def analyze_aia(uploaded_files):
|
|
235 |
all_results.append("Falha ao abrir o arquivo .aia como um arquivo zip.")
|
236 |
except Exception as e:
|
237 |
all_results.append(f"Erro ao processar o arquivo {file_path}: {str(e)}")
|
|
|
|
|
238 |
combined_results_df = pd.concat(all_results, ignore_index=True)
|
239 |
html_result = combined_results_df.to_html(escape=False, classes="output-html")
|
240 |
return output_style + f'<div class="output-container">{html_result}</div>'
|
241 |
|
242 |
iface = gr.Interface(
|
243 |
fn=analyze_aia,
|
244 |
-
inputs=gr.Files(label="Upload .aia Files"),
|
245 |
outputs=gr.HTML(),
|
246 |
title="AIA-Scope",
|
247 |
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.",
|
248 |
-
examples=[["example2.aia"]], # ..
|
249 |
live=False
|
250 |
)
|
251 |
|
252 |
if __name__ == "__main__":
|
253 |
iface.launch(debug=True)
|
|
|
|
|
|
|
|
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:
|
|
|
56 |
return extensions
|
57 |
|
58 |
def count_events_in_bky_file(bky_content):
|
59 |
+
# Counting the number of occurrences of the "component_event" blocks
|
60 |
return bky_content.count('<block type="component_event"')
|
61 |
|
62 |
def extract_app_name_from_scm_files(temp_dir):
|
|
|
64 |
for scm_file in scm_files:
|
65 |
with open(scm_file, 'r', encoding='utf-8', errors='ignore') as file:
|
66 |
content = file.read()
|
67 |
+
|
68 |
+
# Tenta várias expressões regulares para encontrar o nome do aplicativo
|
69 |
regex_patterns = [
|
70 |
r'"AppName"\s*:\s*"([^"]+)"',
|
71 |
+
r'"AppName"\s*:\s*\'([^\']+)\'' # Exemplo de outra possível expressão regular
|
72 |
]
|
73 |
+
|
74 |
for pattern in regex_patterns:
|
75 |
app_name_match = re.search(pattern, content)
|
76 |
if app_name_match:
|
77 |
return app_name_match.group(1)
|
78 |
+
|
79 |
+
# Log de erros ou avisos
|
80 |
print(f"Aviso: Nome do aplicativo não encontrado no diretório {temp_dir}")
|
81 |
return "N/A"
|
82 |
|
83 |
def extract_project_info_from_properties(file_path):
|
84 |
+
# Initialize variables
|
85 |
timestamp = "N/A"
|
86 |
app_name = "N/A"
|
87 |
app_version = "N/A"
|
88 |
authURL = "ai2.appinventor.mit.edu"
|
89 |
|
90 |
+
# Create a temporary directory
|
91 |
with tempfile.TemporaryDirectory() as temp_dir:
|
92 |
with ZipFile(file_path, 'r') as zip_ref:
|
93 |
zip_ref.extractall(temp_dir)
|
94 |
+
# Define the path to the 'project.properties' file
|
95 |
project_properties_file_path = 'youngandroidproject/project.properties'
|
96 |
+
|
97 |
+
# Check if the file exists in the .aia file
|
98 |
if project_properties_file_path in zip_ref.namelist():
|
99 |
with zip_ref.open(project_properties_file_path) as file:
|
100 |
project_properties_lines = file.read().decode('utf-8').splitlines()
|
101 |
+
|
102 |
+
# Extracting timestamp
|
103 |
timestamp = project_properties_lines[1] if len(project_properties_lines) > 1 else "N/A"
|
104 |
+
|
105 |
+
# Extracting app name and version using regular expressions
|
106 |
for line in project_properties_lines:
|
107 |
app_name_match = re.match(r'aname=(.*)', line)
|
108 |
if app_name_match:
|
109 |
app_name = app_name_match.group(1)
|
110 |
+
|
111 |
app_version_match = re.match(r'versionname=(.*)', line)
|
112 |
if app_version_match:
|
113 |
app_version = app_version_match.group(1)
|
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,
|
126 |
'app_name': app_name,
|
|
|
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:
|
|
|
282 |
all_results.append("Falha ao abrir o arquivo .aia como um arquivo zip.")
|
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 |
+
|