Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ import base64
|
|
| 6 |
import yaml
|
| 7 |
from tools.final_answer import FinalAnswerTool
|
| 8 |
from Gradio_UI import GradioUI
|
|
|
|
| 9 |
import os
|
| 10 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
momo_key = os.getenv("MomoKey")
|
|
@@ -122,6 +123,68 @@ def search_quran_advanced(search_terms: list, operator: str = "VAND") -> str:
|
|
| 122 |
return f"No results found for '{query_string}'."
|
| 123 |
else:
|
| 124 |
return "Error: Could not fetch data from the Quran API."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
@tool
|
| 127 |
def calculate_expenses(sallery: int) -> str:
|
|
@@ -200,7 +263,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 200 |
|
| 201 |
agent = CodeAgent(
|
| 202 |
model=model,
|
| 203 |
-
tools=[final_answer, calculate_expenses, image_generation_tool, encode_text, decode_text, get_sura, search_quran, search_quran_advanced],
|
| 204 |
max_steps=6,
|
| 205 |
verbosity_level=1,
|
| 206 |
grammar=None,
|
|
|
|
| 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 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 12 |
momo_key = os.getenv("MomoKey")
|
|
|
|
| 123 |
return f"No results found for '{query_string}'."
|
| 124 |
else:
|
| 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_number: int, verse_number: int) -> Tuple[List[int], int]:
|
| 130 |
+
"""A tool that calculates the Abjad values (Gematrical values) of Arabic letters in a given text.
|
| 131 |
+
The function considers variations of letters that share the same Abjad value, such as:
|
| 132 |
+
- ا أ إ آ ء have the same value of 1
|
| 133 |
+
- ي ئ ى have the same value of 10
|
| 134 |
+
- و ؤ have the same value of 6
|
| 135 |
+
- ه ة have the same value of 5
|
| 136 |
+
|
| 137 |
+
The function returns a tuple containing:
|
| 138 |
+
- A list of individual Abjad values for each letter in the text.
|
| 139 |
+
- The total Abjad value for the entire text.
|
| 140 |
+
|
| 141 |
+
Args:
|
| 142 |
+
sura_number (int): the number of the Sura in the Quran
|
| 143 |
+
verse_number (int): the number of the verse in the given Sura in the Quran
|
| 144 |
+
|
| 145 |
+
Returns:
|
| 146 |
+
tuple: A tuple containing two elements:
|
| 147 |
+
1. A list of integers representing the Abjad value for each letter in the text.
|
| 148 |
+
2. An integer representing the total Abjad value of the entire text.
|
| 149 |
+
|
| 150 |
+
Example:
|
| 151 |
+
calculate_abjad_value("بسم الله الرحمن الرحيم")
|
| 152 |
+
Returns:
|
| 153 |
+
([2, 60, 40, 1, 30, 30, 5, 1, 30, 200, 8, 40, 50, 1, 30, 200, 8, 10, 40], 786)
|
| 154 |
+
"""
|
| 155 |
+
abjad_dict = {
|
| 156 |
+
'ا': 1, 'أ': 1, 'إ': 1, 'آ': 1, 'ء': 1,
|
| 157 |
+
'ب': 2, 'ت': 400, 'ث': 500, 'ج': 3, 'ح': 8, 'خ': 600,
|
| 158 |
+
'د': 4, 'ذ': 700, 'ر': 200, 'ز': 7, 'س': 60, 'ش': 300,
|
| 159 |
+
'ص': 90, 'ض': 800, 'ط': 9, 'ظ': 900, 'ع': 70, 'غ': 1000,
|
| 160 |
+
'ف': 80, 'ق': 100, 'ك': 20, 'ل': 30, 'م': 40, 'ن': 50,
|
| 161 |
+
'ه': 5, 'و': 6, 'ى': 10, 'ي': 10, 'ئ': 10, 'ؤ': 6, 'ة': 5
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
expression = ''
|
| 165 |
+
url = f"https://quran-challenge.com/app/php/getverse.php?sura_number={sura_number}&verse_number={verse_number}"
|
| 166 |
+
response = requests.get(url)
|
| 167 |
+
|
| 168 |
+
if response.status_code == 200:
|
| 169 |
+
data = response.json()
|
| 170 |
+
result = ""
|
| 171 |
+
|
| 172 |
+
for verse in data:
|
| 173 |
+
nr = verse['nr']
|
| 174 |
+
text = verse['text']
|
| 175 |
+
expression = f"{text}"
|
| 176 |
+
|
| 177 |
+
expression = expression.replace(" ", "") # Remove spaces from the expression
|
| 178 |
+
individual_values = []
|
| 179 |
+
total_value = 0
|
| 180 |
+
|
| 181 |
+
for letter in expression:
|
| 182 |
+
if letter in abjad_dict:
|
| 183 |
+
value = abjad_dict[letter]
|
| 184 |
+
individual_values.append(value)
|
| 185 |
+
total_value += value
|
| 186 |
+
|
| 187 |
+
return individual_values, total_value
|
| 188 |
|
| 189 |
@tool
|
| 190 |
def calculate_expenses(sallery: int) -> str:
|
|
|
|
| 263 |
|
| 264 |
agent = CodeAgent(
|
| 265 |
model=model,
|
| 266 |
+
tools=[final_answer, calculate_expenses, image_generation_tool, encode_text, decode_text, get_sura, search_quran, search_quran_advanced, abjad_value],
|
| 267 |
max_steps=6,
|
| 268 |
verbosity_level=1,
|
| 269 |
grammar=None,
|