Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool,
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import base64
|
| 6 |
import yaml
|
| 7 |
-
from
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
from typing import List, Tuple
|
| 10 |
import os
|
| 11 |
|
| 12 |
momo_key = os.getenv("MomoKey")
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
-
|
| 15 |
def my_custom_tool(arg1:str, arg2:int)-> str:
|
| 16 |
"""A tool that does nothing yet.
|
| 17 |
Args:
|
|
@@ -20,7 +20,7 @@ def my_custom_tool(arg1:str, arg2:int)-> str:
|
|
| 20 |
"""
|
| 21 |
return "What magic will you build ?"
|
| 22 |
|
| 23 |
-
|
| 24 |
def get_sura(sura_number: int) -> str:
|
| 25 |
"""A tool that gets the text of a sura based on its sura number
|
| 26 |
Args:
|
|
@@ -40,7 +40,7 @@ def get_sura(sura_number: int) -> str:
|
|
| 40 |
return f"The text of the sura {sura_number} is:\n {result}"
|
| 41 |
else:
|
| 42 |
return "Error: Could not fetch the sura data."
|
| 43 |
-
|
| 44 |
def search_quran(search_type: str, search_value: str) -> str:
|
| 45 |
"""A tool that searches for a given term in the Quran based on the specified search type. The spellingspecial search type indicates the othmani original spelling of the text.
|
| 46 |
|
|
@@ -76,7 +76,7 @@ def search_quran(search_type: str, search_value: str) -> str:
|
|
| 76 |
else:
|
| 77 |
return "Error: Could not fetch data from the Quran API."
|
| 78 |
|
| 79 |
-
|
| 80 |
def search_quran_advanced(search_terms: list, operator: str = "VAND") -> str:
|
| 81 |
"""A tool that searches for multiple terms in the same verse in the Quran using AND/OR conditions.
|
| 82 |
The AND condition is named: VAND and the OR condition is named VOR. The prefix V stands for "Verse", where the search happens on verse level.
|
|
@@ -125,7 +125,7 @@ def search_quran_advanced(search_terms: list, operator: str = "VAND") -> str:
|
|
| 125 |
return "Error: Could not fetch data from the Quran API."
|
| 126 |
from typing import List, Tuple
|
| 127 |
|
| 128 |
-
|
| 129 |
def abjad_value(sura: int, verse: int) -> Tuple[List[int], int]:
|
| 130 |
"""A tool that calculates the Abjad values (Gematrical values) of Arabic letters in a given text and returns a tuple containing:
|
| 131 |
- A list of individual Abjad values for each letter in the text.
|
|
@@ -179,7 +179,7 @@ def abjad_value(sura: int, verse: int) -> Tuple[List[int], int]:
|
|
| 179 |
|
| 180 |
return individual_values, total_value
|
| 181 |
|
| 182 |
-
|
| 183 |
def calculate_expenses(sallery: int) -> str:
|
| 184 |
"""A tool that calculate the expenses of a given sallery.
|
| 185 |
Args:
|
|
@@ -187,7 +187,7 @@ def calculate_expenses(sallery: int) -> str:
|
|
| 187 |
"""
|
| 188 |
return f"the expenses of the sallery {sallery} are: {sallery * 0.82 + (sallery * (0.03))} CHF."
|
| 189 |
|
| 190 |
-
|
| 191 |
def encode_text(text: str) -> str:
|
| 192 |
"""Encodes text using XOR with a key and Base64 encoding.
|
| 193 |
|
|
@@ -201,7 +201,7 @@ def encode_text(text: str) -> str:
|
|
| 201 |
encoded_bytes = bytes([ord(c) ^ next(key_cycle) for c in text]) # XOR each char
|
| 202 |
return base64.b64encode(encoded_bytes).decode()
|
| 203 |
|
| 204 |
-
|
| 205 |
def decode_text(encoded_text: str) -> str:
|
| 206 |
"""Decodes a Base64-encoded XOR encrypted text using the given key.
|
| 207 |
|
|
@@ -215,7 +215,7 @@ def decode_text(encoded_text: str) -> str:
|
|
| 215 |
decoded_bytes = base64.b64decode(encoded_text) # Decode Base64
|
| 216 |
return ''.join(chr(b ^ next(key_cycle)) for b in decoded_bytes)
|
| 217 |
|
| 218 |
-
|
| 219 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 220 |
"""A tool that fetches the current local time in a specified timezone.
|
| 221 |
Args:
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool, OpenAIServerModel
|
| 2 |
import datetime
|
| 3 |
import requests
|
| 4 |
import pytz
|
| 5 |
import base64
|
| 6 |
import yaml
|
| 7 |
+
from tools.final_answer import FinalAnswerTool
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
from typing import List, Tuple
|
| 10 |
import os
|
| 11 |
|
| 12 |
momo_key = os.getenv("MomoKey")
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 14 |
+
@tool
|
| 15 |
def my_custom_tool(arg1:str, arg2:int)-> str:
|
| 16 |
"""A tool that does nothing yet.
|
| 17 |
Args:
|
|
|
|
| 20 |
"""
|
| 21 |
return "What magic will you build ?"
|
| 22 |
|
| 23 |
+
@tool
|
| 24 |
def get_sura(sura_number: int) -> str:
|
| 25 |
"""A tool that gets the text of a sura based on its sura number
|
| 26 |
Args:
|
|
|
|
| 40 |
return f"The text of the sura {sura_number} is:\n {result}"
|
| 41 |
else:
|
| 42 |
return "Error: Could not fetch the sura data."
|
| 43 |
+
@tool
|
| 44 |
def search_quran(search_type: str, search_value: str) -> str:
|
| 45 |
"""A tool that searches for a given term in the Quran based on the specified search type. The spellingspecial search type indicates the othmani original spelling of the text.
|
| 46 |
|
|
|
|
| 76 |
else:
|
| 77 |
return "Error: Could not fetch data from the Quran API."
|
| 78 |
|
| 79 |
+
@tool
|
| 80 |
def search_quran_advanced(search_terms: list, operator: str = "VAND") -> str:
|
| 81 |
"""A tool that searches for multiple terms in the same verse in the Quran using AND/OR conditions.
|
| 82 |
The AND condition is named: VAND and the OR condition is named VOR. The prefix V stands for "Verse", where the search happens on verse level.
|
|
|
|
| 125 |
return "Error: Could not fetch data from the Quran API."
|
| 126 |
from typing import List, Tuple
|
| 127 |
|
| 128 |
+
@tool
|
| 129 |
def abjad_value(sura: int, verse: int) -> Tuple[List[int], int]:
|
| 130 |
"""A tool that calculates the Abjad values (Gematrical values) of Arabic letters in a given text and returns a tuple containing:
|
| 131 |
- A list of individual Abjad values for each letter in the text.
|
|
|
|
| 179 |
|
| 180 |
return individual_values, total_value
|
| 181 |
|
| 182 |
+
@tool
|
| 183 |
def calculate_expenses(sallery: int) -> str:
|
| 184 |
"""A tool that calculate the expenses of a given sallery.
|
| 185 |
Args:
|
|
|
|
| 187 |
"""
|
| 188 |
return f"the expenses of the sallery {sallery} are: {sallery * 0.82 + (sallery * (0.03))} CHF."
|
| 189 |
|
| 190 |
+
@tool
|
| 191 |
def encode_text(text: str) -> str:
|
| 192 |
"""Encodes text using XOR with a key and Base64 encoding.
|
| 193 |
|
|
|
|
| 201 |
encoded_bytes = bytes([ord(c) ^ next(key_cycle) for c in text]) # XOR each char
|
| 202 |
return base64.b64encode(encoded_bytes).decode()
|
| 203 |
|
| 204 |
+
@tool
|
| 205 |
def decode_text(encoded_text: str) -> str:
|
| 206 |
"""Decodes a Base64-encoded XOR encrypted text using the given key.
|
| 207 |
|
|
|
|
| 215 |
decoded_bytes = base64.b64decode(encoded_text) # Decode Base64
|
| 216 |
return ''.join(chr(b ^ next(key_cycle)) for b in decoded_bytes)
|
| 217 |
|
| 218 |
+
@tool
|
| 219 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 220 |
"""A tool that fetches the current local time in a specified timezone.
|
| 221 |
Args:
|