SergeyO7 commited on
Commit
f08be6b
·
verified ·
1 Parent(s): 87f52ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +178 -2
app.py CHANGED
@@ -43,7 +43,8 @@ ZODIAC_SIGNS = [
43
  ("Gemini", 60, 90),
44
  ("Cancer", 90, 120),
45
  ("Leo", 120, 150),
46
- ("Virgo", 150, 180),
 
47
  ("Libra", 180, 210),
48
  ("Scorpio", 210, 240),
49
  ("Sagittarius", 240, 270),
@@ -120,6 +121,38 @@ PRUNING_PHASE_COEFFS = {
120
  "Waning Moon": 0.5,
121
  }
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  @tool
124
  def get_moon_info(date_time: str) -> dict:
125
  """
@@ -291,6 +324,149 @@ model = HfApiModel(
291
  custom_role_conversions=None,
292
  )
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  # Load image tool from Hub
295
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
296
 
@@ -301,7 +477,7 @@ with open("prompts.yaml", 'r') as stream:
301
  # Initialize agent with all tools
302
  agent = CodeAgent(
303
  model=model,
304
- tools=[final_answer, get_moon_info, get_current_time_in_timezone, get_current_time_raw, image_generation_tool],
305
  max_steps=6,
306
  verbosity_level=1,
307
  prompt_templates=prompt_templates
 
43
  ("Gemini", 60, 90),
44
  ("Cancer", 90, 120),
45
  ("Leo", 120, 150),
46
+ ("Virgo"
47
+ , 150, 180),
48
  ("Libra", 180, 210),
49
  ("Scorpio", 210, 240),
50
  ("Sagittarius", 240, 270),
 
121
  "Waning Moon": 0.5,
122
  }
123
 
124
+ # Translation dictionaries
125
+ classification_ru = {
126
+ 'Swallowed': 'проглоченная',
127
+ 'Tiny': 'сверхмалая',
128
+ 'Small': 'малая',
129
+ 'Normal': 'нормальная',
130
+ 'Ideal': 'идеальная',
131
+ 'Big': 'большая'
132
+ }
133
+
134
+ planet_ru = {
135
+ 'Sun': 'Солнце',
136
+ 'Moon': 'Луна',
137
+ 'Mercury': 'Меркурий',
138
+ 'Venus': 'Венера',
139
+ 'Mars': 'Марс',
140
+ 'Jupiter': 'Юпитер',
141
+ 'Saturn': 'Сатурн'
142
+ }
143
+
144
+ planet_symbols = {
145
+ 'Sun': '☉',
146
+ 'Moon': '☾',
147
+ 'Mercury': '☿',
148
+ 'Venus': '♀',
149
+ 'Mars': '♂',
150
+ 'Jupiter': '♃',
151
+ 'Saturn': '♄'
152
+ }
153
+
154
+
155
+
156
  @tool
157
  def get_moon_info(date_time: str) -> dict:
158
  """
 
324
  custom_role_conversions=None,
325
  )
326
 
327
+ # Function to calculate PLadder and zone sizes
328
+ @tool
329
+ def PLadder_ZSizes(date_time_iso: str):
330
+ """
331
+ Calculate the planetary ladder and zone sizes for a given date and time.
332
+
333
+ Args:
334
+ date_time_iso (str): Date and time in ISO format (e.g., '2023-10-10T12:00:00')
335
+
336
+ Returns:
337
+ dict: Contains 'PLadder' (list of planets) and 'ZSizes' (list of zone sizes with classifications)
338
+ or an error message if unsuccessful
339
+ """
340
+ try:
341
+ dt = datetime.fromisoformat(date_time_iso)
342
+ if dt.year < 1900 or dt.year > 2050:
343
+ return {"error": "Дата вне диапазона. Должна быть между 1900 и 2050 годами."}
344
+
345
+ # Load ephemeris
346
+ planets = load('de421.bsp')
347
+ earth = planets['earth']
348
+
349
+ # Define planet objects
350
+ planet_objects = {
351
+ 'Sun': planets['sun'],
352
+ 'Moon': planets['moon'],
353
+ 'Mercury': planets['mercury'],
354
+ 'Venus': planets['venus'],
355
+ 'Mars': planets['mars'],
356
+ 'Jupiter': planets['jupiter barycenter'],
357
+ 'Saturn': planets['saturn barycenter']
358
+ }
359
+
360
+ # Create time object
361
+ ts = load.timescale()
362
+ t = ts.utc(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second)
363
+
364
+ # Compute ecliptic longitudes
365
+ longitudes = {}
366
+ for planet in planet_objects:
367
+ apparent = earth.at(t).observe(planet_objects[planet]).apparent()
368
+ _, lon, _ = apparent.ecliptic_latlon()
369
+ longitudes[planet] = lon.degrees
370
+
371
+ # Sort planets by longitude to form PLadder
372
+ sorted_planets = sorted(longitudes.items(), key=lambda x: x[1])
373
+ PLadder = [p for p, _ in sorted_planets]
374
+ sorted_lons = [lon for _, lon in sorted_planets]
375
+
376
+ # Calculate zone sizes
377
+ zone_sizes = [sorted_lons[0]] + [sorted_lons[i+1] - sorted_lons[i] for i in range(6)] + [360 - sorted_lons[6]]
378
+
379
+ # Determine bordering planets for classification
380
+ bordering = [[PLadder[0]]] + [[PLadder[i-1], PLadder[i]] for i in range(1, 7)] + [[PLadder[6]]]
381
+
382
+ # Classify each zone
383
+ ZSizes = []
384
+ for i, size in enumerate(zone_sizes):
385
+ bord = bordering[i]
386
+ if any(p in ['Sun', 'Moon'] for p in bord):
387
+ X = 7
388
+ elif any(p in ['Mercury', 'Venus', 'Mars'] for p in bord):
389
+ X = 6
390
+ else:
391
+ X = 5
392
+
393
+ if size <= 1:
394
+ classification = 'Swallowed'
395
+ elif size <= X:
396
+ classification = 'Tiny'
397
+ elif size <= 40:
398
+ classification = 'Small'
399
+ elif size < 60:
400
+ if 50 <= size <= 52:
401
+ classification = 'Ideal'
402
+ else:
403
+ classification = 'Normal'
404
+ else:
405
+ classification = 'Big'
406
+
407
+ # Convert size to degrees and minutes
408
+ d = int(size)
409
+ m = int((size - d) * 60)
410
+ size_str = f"{d}°{m}'"
411
+ ZSizes.append((size_str, classification))
412
+
413
+ return {'PLadder': PLadder, 'ZSizes': ZSizes}
414
+
415
+ except ValueError:
416
+ return {"error": "Неверный формат даты и времени. Используйте ISO формат, например, '2023-10-10T12:00:00'"}
417
+ except Exception as e:
418
+ return {"error": f"Ошибка при вычислении: {str(e)}"}
419
+
420
+
421
+ # Function to parse date and time into ISO format
422
+ def parse_date_time(date_time_str):
423
+ try:
424
+ dt = parser.parse(date_time_str)
425
+ return dt.isoformat()
426
+ except ValueError:
427
+ return None
428
+
429
+ # Function to convert longitude to zodiac sign and degrees
430
+ def lon_to_sign(lon):
431
+ signs = ["Овен", "Телец", "Близнецы", "Рак", "Лев", "Дева",
432
+ "Весы", "Скорпион", "Стрелец", "Козерог", "Водолей", "Рыбы"]
433
+ sign_index = int(lon // 30)
434
+ sign = signs[sign_index]
435
+ degrees = int(lon % 30)
436
+ minutes = int((lon % 1) * 60)
437
+ return f"{sign} {degrees}°{minutes}'"
438
+
439
+
440
+ @tool
441
+ def plot_pladder(PLadder):
442
+ """
443
+ Plot the planetary ladder as a right triangle with planet symbols.
444
+
445
+ Args:
446
+ PLadder (list): List of planet names in order
447
+
448
+ Returns:
449
+ matplotlib.figure.Figure: The generated plot
450
+ """
451
+ fig, ax = plt.subplots()
452
+ # Plot triangle with right angle on top: vertices at (0,0), (1.5,3), (3,0)
453
+ ax.plot([0, 1.5, 3, 0], [0, 3, 0, 0], 'k-')
454
+ # Draw horizontal lines dividing height into three equal parts
455
+ ax.plot([0, 3], [1, 1], 'k--')
456
+ ax.plot([0, 3], [2, 2], 'k--')
457
+ # Define positions for planets 1 to 7, adjusted to avoid overlap
458
+ positions = [(0.2, 0.2), (0.2, 1.2), (0.2, 2.2), (1.5, 3.2), (2.8, 2.2), (2.8, 1.2), (2.8, 0.2)]
459
+ for i, pos in enumerate(positions):
460
+ symbol = planet_symbols[PLadder[i]]
461
+ ax.text(pos[0], pos[1], symbol, ha='center', va='center', fontsize=24) # Doubled font size
462
+ ax.set_xlim(-0.5, 3.5)
463
+ ax.set_ylim(-0.5, 3.5)
464
+ ax.set_aspect('equal')
465
+ ax.axis('off')
466
+ return fig
467
+
468
+
469
+
470
  # Load image tool from Hub
471
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
472
 
 
477
  # Initialize agent with all tools
478
  agent = CodeAgent(
479
  model=model,
480
+ tools=[final_answer, get_moon_info, get_current_time_in_timezone, get_current_time_raw, plot_pladder, PLadder_ZSizes, image_generation_tool],
481
  max_steps=6,
482
  verbosity_level=1,
483
  prompt_templates=prompt_templates