semihangin commited on
Commit
e8a77e2
·
verified ·
1 Parent(s): da9051c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -38
app.py CHANGED
@@ -10,49 +10,49 @@ from Gradio_UI import GradioUI
10
 
11
  @tool
12
  def task_manager(action: str, task_data: str = "") -> str:
13
- """Günlük görevleri yönetmek için kullanılan bir araç.
14
 
15
  Args:
16
- action: Yapılacak işlem ("add", "list", "complete", "delete" veya "help")
17
- task_data: Görevle ilgili ek bilgiler (görev açıklaması, görev ID'si vs.)
18
 
19
  Returns:
20
- İşlem sonucu hakkında bilgi içeren bir metin
21
  """
22
  import json
23
  import os
24
  from datetime import datetime
25
 
26
- # Görev verilerini saklayacak dosya
27
  TASKS_FILE = "tasks.json"
28
 
29
- # Eğer dosya yoksa boş bir görev listesi oluştur
30
  if not os.path.exists(TASKS_FILE):
31
  with open(TASKS_FILE, "w") as f:
32
  json.dump({"tasks": []}, f)
33
 
34
- # Görevleri yükle
35
  with open(TASKS_FILE, "r") as f:
36
  data = json.load(f)
37
 
38
- # Görev listesi
39
  tasks = data["tasks"]
40
 
41
- # Yardım mesajı
42
  if action == "help" or action == "":
43
- return """Görev Yönetici Aracı Kullanımı:
44
- - add: Yeni görev ekle (örn: task_manager("add", "Marketten süt al"))
45
- - list: Tüm görevleri listele (örn: task_manager("list"))
46
- - complete: Görevi tamamlandı olarak işaretle (örn: task_manager("complete", "1"))
47
- - delete: Görevi sil (örn: task_manager("delete", "1"))
48
- - help: Bu yardım mesajını göster"""
49
 
50
- # Yeni görev ekle
51
  elif action == "add":
52
  if not task_data:
53
- return "Hata: Görev açıklaması boş olamaz!"
54
 
55
- # Yeni görev oluştur
56
  new_task = {
57
  "id": len(tasks) + 1,
58
  "description": task_data,
@@ -60,21 +60,21 @@ def task_manager(action: str, task_data: str = "") -> str:
60
  "completed": False
61
  }
62
 
63
- # Görevi listeye ekle
64
  tasks.append(new_task)
65
 
66
- # Değişiklikleri kaydet
67
  with open(TASKS_FILE, "w") as f:
68
  json.dump(data, f, indent=2)
69
 
70
- return f"Görev eklendi: {task_data} (ID: {new_task['id']})"
71
 
72
- # Görevleri listele
73
  elif action == "list":
74
  if not tasks:
75
- return "Görev listeniz boş."
76
 
77
- result = "GÖREVLERİNİZ:\n"
78
  result += "-" * 50 + "\n"
79
 
80
  for task in tasks:
@@ -83,51 +83,51 @@ def task_manager(action: str, task_data: str = "") -> str:
83
 
84
  return result
85
 
86
- # Görevi tamamlandı olarak işaretle
87
  elif action == "complete":
88
  try:
89
  task_id = int(task_data)
90
 
91
- # ID'ye göre görevi bul
92
  for task in tasks:
93
  if task["id"] == task_id:
94
  task["completed"] = True
95
 
96
- # Değişiklikleri kaydet
97
  with open(TASKS_FILE, "w") as f:
98
  json.dump(data, f, indent=2)
99
 
100
- return f"Görev tamamlandı: {task['description']}"
101
 
102
- return f"Hata: ID {task_id} olan görev bulunamadı."
103
 
104
  except ValueError:
105
- return "Hata: Geçerli bir görev ID'si belirtmelisiniz."
106
 
107
- # Görevi sil
108
  elif action == "delete":
109
  try:
110
  task_id = int(task_data)
111
 
112
- # ID'ye göre görevi bul
113
  for i, task in enumerate(tasks):
114
  if task["id"] == task_id:
115
- # Görevi listeden kaldır
116
  deleted_task = tasks.pop(i)
117
 
118
- # Değişiklikleri kaydet
119
  with open(TASKS_FILE, "w") as f:
120
  json.dump(data, f, indent=2)
121
 
122
- return f"Görev silindi: {deleted_task['description']}"
123
 
124
- return f"Hata: ID {task_id} olan görev bulunamadı."
125
 
126
  except ValueError:
127
- return "Hata: Geçerli bir görev ID'si belirtmelisiniz."
128
 
129
  else:
130
- return f"Hata: Bilinmeyen eylem '{action}'. Geçerli eylemler: add, list, complete, delete, help"
131
 
132
  @tool
133
  def get_current_time_in_timezone(timezone: str) -> str:
 
10
 
11
  @tool
12
  def task_manager(action: str, task_data: str = "") -> str:
13
+ """A tool for managing daily tasks.
14
 
15
  Args:
16
+ action: The operation to perform ("add", "list", "complete", "delete", or "help")
17
+ task_data: Additional information related to the task (task description, task ID, etc.)
18
 
19
  Returns:
20
+ A text containing information about the result of the operation
21
  """
22
  import json
23
  import os
24
  from datetime import datetime
25
 
26
+ # File to store task data
27
  TASKS_FILE = "tasks.json"
28
 
29
+ # Create an empty task list if the file doesn't exist
30
  if not os.path.exists(TASKS_FILE):
31
  with open(TASKS_FILE, "w") as f:
32
  json.dump({"tasks": []}, f)
33
 
34
+ # Load tasks
35
  with open(TASKS_FILE, "r") as f:
36
  data = json.load(f)
37
 
38
+ # Task list
39
  tasks = data["tasks"]
40
 
41
+ # Help message
42
  if action == "help" or action == "":
43
+ return """Task Manager Tool Usage:
44
+ - add: Add a new task (e.g.: task_manager("add", "Buy milk from the store"))
45
+ - list: List all tasks (e.g.: task_manager("list"))
46
+ - complete: Mark a task as completed (e.g.: task_manager("complete", "1"))
47
+ - delete: Delete a task (e.g.: task_manager("delete", "1"))
48
+ - help: Show this help message"""
49
 
50
+ # Add a new task
51
  elif action == "add":
52
  if not task_data:
53
+ return "Error: Task description cannot be empty!"
54
 
55
+ # Create a new task
56
  new_task = {
57
  "id": len(tasks) + 1,
58
  "description": task_data,
 
60
  "completed": False
61
  }
62
 
63
+ # Add the task to the list
64
  tasks.append(new_task)
65
 
66
+ # Save changes
67
  with open(TASKS_FILE, "w") as f:
68
  json.dump(data, f, indent=2)
69
 
70
+ return f"Task added: {task_data} (ID: {new_task['id']})"
71
 
72
+ # List tasks
73
  elif action == "list":
74
  if not tasks:
75
+ return "Your task list is empty."
76
 
77
+ result = "YOUR TASKS:\n"
78
  result += "-" * 50 + "\n"
79
 
80
  for task in tasks:
 
83
 
84
  return result
85
 
86
+ # Mark task as completed
87
  elif action == "complete":
88
  try:
89
  task_id = int(task_data)
90
 
91
+ # Find task by ID
92
  for task in tasks:
93
  if task["id"] == task_id:
94
  task["completed"] = True
95
 
96
+ # Save changes
97
  with open(TASKS_FILE, "w") as f:
98
  json.dump(data, f, indent=2)
99
 
100
+ return f"Task completed: {task['description']}"
101
 
102
+ return f"Error: Task with ID {task_id} not found."
103
 
104
  except ValueError:
105
+ return "Error: You must specify a valid task ID."
106
 
107
+ # Delete task
108
  elif action == "delete":
109
  try:
110
  task_id = int(task_data)
111
 
112
+ # Find task by ID
113
  for i, task in enumerate(tasks):
114
  if task["id"] == task_id:
115
+ # Remove task from the list
116
  deleted_task = tasks.pop(i)
117
 
118
+ # Save changes
119
  with open(TASKS_FILE, "w") as f:
120
  json.dump(data, f, indent=2)
121
 
122
+ return f"Task deleted: {deleted_task['description']}"
123
 
124
+ return f"Error: Task with ID {task_id} not found."
125
 
126
  except ValueError:
127
+ return "Error: You must specify a valid task ID."
128
 
129
  else:
130
+ return f"Error: Unknown action '{action}'. Valid actions: add, list, complete, delete, help"
131
 
132
  @tool
133
  def get_current_time_in_timezone(timezone: str) -> str: