Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- README.md +9 -12
- app.py +94 -19
- requirements.txt +7 -0
README.md
CHANGED
|
@@ -1,18 +1,15 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.15.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
tags:
|
| 11 |
-
-
|
| 12 |
-
-
|
| 13 |
-
-
|
| 14 |
-
-
|
| 15 |
-
- agent-course
|
| 16 |
---
|
| 17 |
-
|
| 18 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Astrological Birth Chart Generator
|
| 3 |
+
emoji: 🌟
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: gradio
|
|
|
|
| 7 |
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
tags:
|
| 11 |
+
- astrology
|
| 12 |
+
- kerykeion
|
| 13 |
+
- birth-chart
|
| 14 |
+
- gradio
|
|
|
|
| 15 |
---
|
|
|
|
|
|
app.py
CHANGED
|
@@ -4,20 +4,12 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
-
@tool
|
| 12 |
-
def my_cutom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
-
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
-
Args:
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 18 |
-
"""
|
| 19 |
-
return "What magic will you build ?"
|
| 20 |
-
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -33,16 +25,61 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
model = HfApiModel(
|
| 39 |
-
max_tokens=2096,
|
| 40 |
-
temperature=0.5,
|
| 41 |
-
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud'
|
| 42 |
-
custom_role_conversions=None,
|
| 43 |
)
|
| 44 |
|
| 45 |
-
|
| 46 |
# Import tool from Hub
|
| 47 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
|
|
@@ -51,7 +88,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer],
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
@@ -61,5 +98,43 @@ agent = CodeAgent(
|
|
| 61 |
prompt_templates=prompt_templates
|
| 62 |
)
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from typing import Any, Optional
|
| 8 |
+
import duckduckgo_search
|
| 9 |
+
from kerykeion import AstrologicalSubject, Report, KerykeionChartSVG
|
| 10 |
+
import gradio as gr
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
@tool
|
| 14 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 15 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 27 |
|
| 28 |
+
@tool
|
| 29 |
+
def create_birth_chart(name: str, year: int, month: int, day: int, hour: int, minute: int, city: str, nation: str) -> str:
|
| 30 |
+
"""Creates an astrological birth chart based on user's birth information.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
name: Person's name
|
| 34 |
+
year: Birth year
|
| 35 |
+
month: Birth month
|
| 36 |
+
day: Birth day
|
| 37 |
+
hour: Birth hour
|
| 38 |
+
minute: Birth minute
|
| 39 |
+
city: Birth city
|
| 40 |
+
nation: Birth country
|
| 41 |
+
|
| 42 |
+
Returns:
|
| 43 |
+
str: Path to the generated SVG file and astrological report
|
| 44 |
+
"""
|
| 45 |
+
try:
|
| 46 |
+
# Create birth chart
|
| 47 |
+
person = AstrologicalSubject(
|
| 48 |
+
name=name,
|
| 49 |
+
year=year,
|
| 50 |
+
month=month,
|
| 51 |
+
day=day,
|
| 52 |
+
hour=hour,
|
| 53 |
+
minute=minute,
|
| 54 |
+
city=city,
|
| 55 |
+
nation=nation,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Create SVG file
|
| 59 |
+
chart = KerykeionChartSVG(person)
|
| 60 |
+
svg_path = f"charts/{name.lower().replace(' ', '_')}_birth_chart.svg"
|
| 61 |
+
chart.makeSVG(svg_path)
|
| 62 |
+
|
| 63 |
+
# Create astrological report
|
| 64 |
+
report = Report(person)
|
| 65 |
+
report_text = report.get_full_report()
|
| 66 |
+
|
| 67 |
+
return {
|
| 68 |
+
"svg_path": svg_path,
|
| 69 |
+
"report": report_text
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
except Exception as e:
|
| 73 |
+
return f"Error occurred: {str(e)}"
|
| 74 |
|
| 75 |
final_answer = FinalAnswerTool()
|
| 76 |
model = HfApiModel(
|
| 77 |
+
max_tokens=2096,
|
| 78 |
+
temperature=0.5,
|
| 79 |
+
model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud',
|
| 80 |
+
custom_role_conversions=None,
|
| 81 |
)
|
| 82 |
|
|
|
|
| 83 |
# Import tool from Hub
|
| 84 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 85 |
|
|
|
|
| 88 |
|
| 89 |
agent = CodeAgent(
|
| 90 |
model=model,
|
| 91 |
+
tools=[final_answer, create_birth_chart],
|
| 92 |
max_steps=6,
|
| 93 |
verbosity_level=1,
|
| 94 |
grammar=None,
|
|
|
|
| 98 |
prompt_templates=prompt_templates
|
| 99 |
)
|
| 100 |
|
| 101 |
+
def process_birth_chart(text_input: str):
|
| 102 |
+
"""Processes user input to create a birth chart."""
|
| 103 |
+
try:
|
| 104 |
+
# Send query to agent and get response
|
| 105 |
+
response = agent.run(text_input)
|
| 106 |
+
|
| 107 |
+
if isinstance(response, dict) and "svg_path" in response:
|
| 108 |
+
# Return SVG file and report
|
| 109 |
+
return gr.Image(value=response["svg_path"]), response["report"]
|
| 110 |
+
else:
|
| 111 |
+
return None, "Sorry, couldn't create the birth chart."
|
| 112 |
+
|
| 113 |
+
except Exception as e:
|
| 114 |
+
return None, f"An error occurred: {str(e)}"
|
| 115 |
+
|
| 116 |
+
# Create Gradio interface
|
| 117 |
+
with gr.Blocks() as demo:
|
| 118 |
+
gr.Markdown("# 🌟 Astrological Birth Chart Generator")
|
| 119 |
+
|
| 120 |
+
with gr.Row():
|
| 121 |
+
text_input = gr.Textbox(
|
| 122 |
+
label="Enter Your Birth Information",
|
| 123 |
+
placeholder="Example: My name is John Doe, I was born on May 5, 1990 at 15:30 in Istanbul, Turkey."
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
with gr.Row():
|
| 127 |
+
submit_btn = gr.Button("Generate Birth Chart")
|
| 128 |
+
|
| 129 |
+
with gr.Row():
|
| 130 |
+
chart_output = gr.Image(label="Birth Chart")
|
| 131 |
+
report_output = gr.Textbox(label="Astrological Report", lines=10)
|
| 132 |
+
|
| 133 |
+
submit_btn.click(
|
| 134 |
+
fn=process_birth_chart,
|
| 135 |
+
inputs=[text_input],
|
| 136 |
+
outputs=[chart_output, report_output]
|
| 137 |
+
)
|
| 138 |
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -3,3 +3,10 @@ smolagents
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
requests
|
| 4 |
duckduckgo_search
|
| 5 |
pandas
|
| 6 |
+
kerykeion
|
| 7 |
+
gradio
|
| 8 |
+
pytz
|
| 9 |
+
pyyaml
|
| 10 |
+
python-dateutil
|
| 11 |
+
ephem
|
| 12 |
+
pyswisseph
|