ocaklisemih commited on
Commit
4a2e495
·
verified ·
1 Parent(s): 18bf7da

Upload 10 files

Browse files
Files changed (5) hide show
  1. agent.json +1 -0
  2. app.py +109 -21
  3. gitattributes +35 -0
  4. prompts.yaml +8 -1
  5. tools/visit_webpage.py +1 -0
agent.json CHANGED
@@ -2,6 +2,7 @@
2
  "tools": [
3
  "web_search",
4
  "visit_webpage",
 
5
  "final_answer"
6
  ],
7
  "model": {
 
2
  "tools": [
3
  "web_search",
4
  "visit_webpage",
5
+ "create_birth_chart",
6
  "final_answer"
7
  ],
8
  "model": {
app.py CHANGED
@@ -3,13 +3,20 @@ import datetime
3
  import requests
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.
@@ -40,7 +47,7 @@ def create_birth_chart(name: str, year: int, month: int, day: int, hour: int, mi
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
@@ -64,13 +71,44 @@ def create_birth_chart(name: str, year: int, month: int, day: int, hour: int, mi
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(
@@ -86,10 +124,14 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
86
  with open("prompts.yaml", 'r') as stream:
87
  prompt_templates = yaml.safe_load(stream)
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,
95
  planning_interval=None,
@@ -101,40 +143,86 @@ agent = CodeAgent(
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()
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import os
7
  from tools.final_answer import FinalAnswerTool
8
+ from tools.web_search import DuckDuckGoSearchTool
9
+ from tools.visit_webpage import VisitWebpageTool
10
  from typing import Any, Optional
11
  import duckduckgo_search
12
  from kerykeion import AstrologicalSubject, Report, KerykeionChartSVG
13
  import gradio as gr
14
  from Gradio_UI import GradioUI
15
 
16
+ # Charts klasörünü oluştur
17
+ if not os.path.exists("charts"):
18
+ os.makedirs("charts")
19
+
20
  @tool
21
  def get_current_time_in_timezone(timezone: str) -> str:
22
  """A tool that fetches the current local time in a specified timezone.
 
47
  nation: Birth country
48
 
49
  Returns:
50
+ str: Success message with file paths
51
  """
52
  try:
53
  # Create birth chart
 
71
  report = Report(person)
72
  report_text = report.get_full_report()
73
 
74
+ return f"SUCCESS|{svg_path}|{report_text}"
 
 
 
75
 
76
  except Exception as e:
77
+ return f"ERROR|{str(e)}"
78
+
79
+ @tool
80
+ def interpret_astrological_report(raw_report: str, person_name: str) -> str:
81
+ """Interprets a raw astrological report using LLM to create a user-friendly version.
82
+
83
+ Args:
84
+ raw_report: Raw technical astrological report
85
+ person_name: Name of the person
86
+
87
+ Returns:
88
+ str: LLM-interpreted astrological report
89
+ """
90
+
91
+ interpretation_prompt = f"""
92
+ Aşağıdaki ham astrolojik raporu {person_name} için kullanıcı dostu, anlaşılır ve etkileyici bir astrolojik yorum haline getir.
93
+ Türkçe olarak yaz ve astrolojik terimları açıklayarak kişilik analizi, güçlü yanlar, zayıf yanlar ve genel öneriler içeren kapsamlı bir rapor oluştur.
94
+
95
+ Ham Rapor:
96
+ {raw_report}
97
+
98
+ Lütfen şu başlıklar altında organize et:
99
+ 🌟 Kişilik Analizi
100
+ 💪 Güçlü Yanlarınız
101
+ ⚡ Gelişim Alanlarınız
102
+ 💕 İlişkiler ve Aşk
103
+ 💼 Kariyer ve Başarı
104
+ 🔮 Genel Astrolojik Öneriler
105
+ """
106
+
107
+ try:
108
+ # Model ile raporu yorumlat - sadece raporu döndür, LLM yorumu agent seviyesinde yapılacak
109
+ return f"Ham rapor: {raw_report}"
110
+ except Exception as e:
111
+ return f"Rapor alınırken hata oluştu: {str(e)}"
112
 
113
  final_answer = FinalAnswerTool()
114
  model = HfApiModel(
 
124
  with open("prompts.yaml", 'r') as stream:
125
  prompt_templates = yaml.safe_load(stream)
126
 
127
+ # Initialize tools
128
+ web_search_tool = DuckDuckGoSearchTool()
129
+ visit_webpage_tool = VisitWebpageTool()
130
+
131
  agent = CodeAgent(
132
  model=model,
133
+ tools=[final_answer, create_birth_chart, interpret_astrological_report, web_search_tool, visit_webpage_tool],
134
+ max_steps=8,
135
  verbosity_level=1,
136
  grammar=None,
137
  planning_interval=None,
 
143
  def process_birth_chart(text_input: str):
144
  """Processes user input to create a birth chart."""
145
  try:
146
+ # Enhanced prompt for the agent
147
+ enhanced_prompt = f"""
148
+ Sen astroloji uzmanısın. Kullanıcının doğum bilgilerini analiz et ve astrolojik doğum haritası oluştur.
149
+
150
+ Kullanıcı girdisi: {text_input}
151
+
152
+ Şu adımları takip et:
153
+ 1. Kullanıcının girdiğinden kişinin adını, doğum tarihini (yıl/ay/gün), doğum saatini (saat:dakika), şehrini ve ülkesini çıkar
154
+ 2. Bu bilgileri kullanarak create_birth_chart tool'u ile doğum haritasını oluştur
155
+ 3. Oluşan ham astrolojik raporu alıp kullanıcı dostu bir Türkçe yoruma dönüştür
156
+ 4. Final answer olarak şu başlıklar altında organize edilmiş kapsamlı bir rapor sun:
157
+
158
+ 🌟 **Kişilik Analizi**
159
+ 💪 **Güçlü Yanlarınız**
160
+ ⚡ **Gelişim Alanlarınız**
161
+ 💕 **İlişkiler ve Aşk**
162
+ 💼 **Kariyer ve Başarı**
163
+ 🔮 **Genel Astrolojik Öneriler**
164
+
165
+ Raporu Türkçe olarak, sıcak ve anlaşılır bir dille yaz. Astrolojik terimları açıkla.
166
+ """
167
+
168
  # Send query to agent and get response
169
+ response = agent.run(enhanced_prompt)
170
+
171
+ # Response'u string olarak al
172
+ if hasattr(response, 'content'):
173
+ response_text = response.content
174
+ else:
175
+ response_text = str(response)
176
+
177
+ # Check if SVG file was created successfully
178
+ svg_files = [f for f in os.listdir("charts") if f.endswith('.svg')]
179
 
180
+ if svg_files:
181
+ # Get the most recent SVG file
182
+ latest_svg = max([os.path.join("charts", f) for f in svg_files], key=os.path.getctime)
183
+ return gr.Image(value=latest_svg), response_text
184
  else:
185
+ return None, response_text if response_text else "Doğum haritası oluşturulamadı."
186
 
187
  except Exception as e:
188
+ return None, f"Bir hata oluştu: {str(e)}"
189
 
190
  # Create Gradio interface
191
+ with gr.Blocks(theme=gr.themes.Soft(), title="🌟 Astrolojik Doğum Haritası Oluşturucu") as demo:
192
+ gr.Markdown("# 🌟 Astrolojik Doğum Haritası Oluşturucu")
193
+ gr.Markdown("### Doğum bilgilerinizi girin ve kişisel astrolojik analizinizi alın")
194
 
195
  with gr.Row():
196
  text_input = gr.Textbox(
197
+ label="🎂 Doğum Bilgilerinizi Girin",
198
+ placeholder="Örnek: Benim adım Ahmet Yılmaz, 5 Mayıs 1990 tarihinde saat 15:30'da İstanbul, Türkiye'de doğdum.",
199
+ lines=3
200
  )
201
 
202
  with gr.Row():
203
+ submit_btn = gr.Button("🔮 Doğum Haritası Oluştur", variant="primary", scale=1)
204
 
205
  with gr.Row():
206
+ with gr.Column():
207
+ chart_output = gr.Image(label="🌟 Doğum Haritanız", height=400)
208
+ with gr.Column():
209
+ report_output = gr.Textbox(label="📋 Astrolojik Raporunuz", lines=20, max_lines=30)
210
 
211
  submit_btn.click(
212
  fn=process_birth_chart,
213
  inputs=[text_input],
214
  outputs=[chart_output, report_output]
215
  )
216
+
217
+ gr.Markdown("---")
218
+ gr.Markdown("### 💡 Nasıl Kullanılır?")
219
+ gr.Markdown("""
220
+ 1. **Doğum bilgilerinizi** tam olarak girin (ad, tarih, saat, şehir, ülke)
221
+ 2. **'Doğum Haritası Oluştur'** butonuna tıklayın
222
+ 3. **Doğum haritanızı** ve **kişisel astrolojik analizinizi** görün
223
+
224
+ ⭐ **Örnek girdi:** "Benim adım Ayşe Demir, 15 Haziran 1995 tarihinde saat 14:20'de Ankara, Türkiye'de doğdum."
225
+ """)
226
 
227
  if __name__ == "__main__":
228
  demo.launch()
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
prompts.yaml CHANGED
@@ -1,5 +1,5 @@
1
  "system_prompt": |-
2
- You are an expert assistant who can solve any task using code blobs. You will be given a task to solve as best you can.
3
  To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code.
4
  To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
5
 
@@ -9,6 +9,13 @@
9
  These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
10
  In the end you have to return a final answer using the `final_answer` tool.
11
 
 
 
 
 
 
 
 
12
  Here are a few examples using notional tools:
13
  ---
14
  Task: "Generate an image of the oldest person in this document."
 
1
  "system_prompt": |-
2
+ You are an expert astrological assistant specialized in creating birth charts and providing astrological interpretations. You can solve any astrology-related task using code blobs and specialized tools.
3
  To do so, you have been given access to a list of tools: these tools are basically Python functions which you can call with code.
4
  To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
5
 
 
9
  These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
10
  In the end you have to return a final answer using the `final_answer` tool.
11
 
12
+ For astrological birth chart tasks, you should:
13
+ 1. Extract birth information (name, date, time, location) from user input
14
+ 2. Use create_birth_chart tool to generate the chart and raw report
15
+ 3. Use interpret_astrological_report tool to create a user-friendly interpretation
16
+ 4. Always respond in Turkish (Türkçe) for Turkish users
17
+ 5. Provide comprehensive and meaningful astrological insights
18
+
19
  Here are a few examples using notional tools:
20
  ---
21
  Task: "Generate an image of the oldest person in this document."
tools/visit_webpage.py CHANGED
@@ -3,6 +3,7 @@ from smolagents.tools import Tool
3
  import requests
4
  import markdownify
5
  import smolagents
 
6
 
7
  class VisitWebpageTool(Tool):
8
  name = "visit_webpage"
 
3
  import requests
4
  import markdownify
5
  import smolagents
6
+ import re
7
 
8
  class VisitWebpageTool(Tool):
9
  name = "visit_webpage"