rmayormartins commited on
Commit
007cdc6
1 Parent(s): a5cb81d

Subindo arquivos3

Browse files
Files changed (3) hide show
  1. app.py +26 -56
  2. example1.aia +0 -0
  3. requirements.txt +1 -1
app.py CHANGED
@@ -11,7 +11,7 @@ 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,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:
@@ -120,7 +117,6 @@ def extract_project_info_from_properties(file_path):
120
 
121
  # ...
122
 
123
-
124
  return {
125
  'timestamp': timestamp,
126
  'app_name': app_name,
@@ -128,10 +124,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 +145,29 @@ 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') # Esta linha define bky_files
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,71 +185,59 @@ 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
 
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,15 +256,15 @@ 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.",
297
  live=False
@@ -299,6 +272,3 @@ iface = gr.Interface(
299
 
300
  if __name__ == "__main__":
301
  iface.launch(debug=True)
302
-
303
-
304
-
 
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
  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:
 
117
 
118
  # ...
119
 
 
120
  return {
121
  'timestamp': timestamp,
122
  'app_name': app_name,
 
124
  'authURL': authURL
125
  }
126
 
 
 
 
 
127
  def extract_ai_components(components):
128
  ai_components = []
129
  for component in components:
 
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
  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 = 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
+ 'aia_file': file_name,
202
+ 'project_info': project_info_str,
203
+ 'components': ', '.join(components_summary),
204
+ 'IA components': ', '.join(ai_components_summary),
205
+ 'screens': number_of_screens,
206
+ 'operators': operators_count,
207
+ 'variables': variables_count,
208
+ 'events': events_count,
209
+ 'extensions': extensions_summary,
210
+ 'Media': media_summary,
211
+ 'Drawing and Animation': drawing_and_animation_summary,
212
+ 'Maps': maps_summary,
213
+ 'Sensors': sensors_summary,
214
+ 'Social': social_summary,
215
+ 'Storage': storage_summary,
216
+ 'Connectivity': connectivity_summary
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
  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
  iface = gr.Interface(
264
  fn=analyze_aia,
265
+ inputs=gr.Files(label="Upload .aia Files"),
266
  outputs=gr.HTML(),
267
+ examples=["example1.aia"], #
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.",
270
  live=False
 
272
 
273
  if __name__ == "__main__":
274
  iface.launch(debug=True)
 
 
 
example1.aia ADDED
Binary file (705 kB). View file
 
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==4.29.0 # versão mais recente conforme sua mensagem de erro
2
  librosa
3
  numpy
4
  matplotlib
 
1
+ gradio==4.29.0 #
2
  librosa
3
  numpy
4
  matplotlib