atomkevich commited on
Commit
627060a
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -9
app.py CHANGED
@@ -7,16 +7,48 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  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:
@@ -55,7 +87,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ from langdetect import detect
11
+ import requests
12
+ from smolagents import tool
13
+
14
+ DEEPL_API_KEY = ""
15
+ DEEPL_FREE_ENDPOINT = "https://api-free.deepl.com/v2/translate"
16
+
17
  @tool
18
+ def agent_translate(text: str) -> str:
19
+ """
20
+ A translation tool using free DeepL API.
21
+ 1) If text starts with 'PL:', translate the rest to Polish.
22
+ 2) If detected language == 'ru', translate to English.
23
+ 3) Else translate to Russian.
24
  """
25
+ if text.startswith("PL:"):
26
+ original = text[3:].strip()
27
+ target_lang = "PL"
28
+ else:
29
+ detected_lang = detect(text)
30
+ if detected_lang == "ru":
31
+ target_lang = "EN"
32
+ original = text
33
+ else:
34
+ target_lang = "RU"
35
+ original = text
36
+
37
+ params = {
38
+ "auth_key": DEEPL_API_KEY,
39
+ "text": original,
40
+ "target_lang": target_lang
41
+ }
42
+
43
+ try:
44
+ #response = requests.post(DEEPL_FREE_ENDPOINT, data=params)
45
+ #response.raise_for_status()
46
+ #result = response.json()
47
+ #translated_text = result["translations"][0]["text"]
48
+ #return translated_text
49
+ return ", ".join([detected_lang, target_lang, original])
50
+ except Exception as e:
51
+ return f"Error during translating using DeepL: {str(e)}"
52
 
53
  @tool
54
  def get_current_time_in_timezone(timezone: str) -> str:
 
87
 
88
  agent = CodeAgent(
89
  model=model,
90
+ tools=[agent_translate, final_answer], ## add your tools here (don't remove final answer)
91
  max_steps=6,
92
  verbosity_level=1,
93
  grammar=None,