tkesonia commited on
Commit
026a0ec
·
verified ·
1 Parent(s): bd5583c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -9,30 +9,35 @@ 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_custom_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.
24
  Args:
25
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
26
  """
 
 
 
27
  try:
28
- # Create timezone object
29
- tz = pytz.timezone(timezone)
30
- # Get current time in that timezone
31
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
- return f"The current local time in {timezone} is: {local_time}"
 
 
 
 
 
 
 
 
 
 
 
33
  except Exception as e:
34
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
-
36
 
37
  final_answer = FinalAnswerTool()
38
 
@@ -42,11 +47,10 @@ final_answer = FinalAnswerTool()
42
  model = HfApiModel(
43
  max_tokens=2096,
44
  temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
  custom_role_conversions=None,
47
  )
48
 
49
-
50
  # Import tool from Hub
51
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
52
 
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ # Below is an example of a tool that does nothing. Amaze us with your creativity !
 
 
 
 
 
 
 
 
13
  @tool
14
+ def translate_japanese_to_english(text: str) -> str:
15
+ """A tool that translates any Japanese text written in Hiragana or Kanji to English.
16
  Args:
17
+ text: The Japanese word or sentence to translate.
18
  """
19
+ if not text.strip():
20
+ return "No text provided for translation."
21
+
22
  try:
23
+ # Use LibreTranslate's API to perform the translation.
24
+ response = requests.post(
25
+ "https://libretranslate.de/translate",
26
+ data={
27
+ "q": text,
28
+ "source": "ja",
29
+ "target": "en",
30
+ "format": "text"
31
+ },
32
+ timeout=10 # seconds
33
+ )
34
+ response.raise_for_status() # Raise an exception for HTTP errors
35
+ translated_text = response.json().get("translatedText", "")
36
+ if not translated_text:
37
+ return "Translation failed: No translated text received."
38
+ return translated_text
39
  except Exception as e:
40
+ return f"Error translating text: {str(e)}"
 
41
 
42
  final_answer = FinalAnswerTool()
43
 
 
47
  model = HfApiModel(
48
  max_tokens=2096,
49
  temperature=0.5,
50
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
51
  custom_role_conversions=None,
52
  )
53
 
 
54
  # Import tool from Hub
55
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
56