piotrekgrl commited on
Commit
4438281
·
1 Parent(s): b92f72d

gradio ui wording

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. README.md +1 -1
  3. app.py +2 -1
  4. ui.py +83 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__/
README.md CHANGED
@@ -10,7 +10,7 @@ pinned: false
10
  tags:
11
  - tool
12
  license: apache-2.0
13
- short_description: Python Debuger for LLMs
14
  ---
15
 
16
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
10
  tags:
11
  - tool
12
  license: apache-2.0
13
+ short_description: Python Debuger tool for Smolagents
14
  ---
15
 
16
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,7 +1,8 @@
1
  from smolagents import launch_gradio_demo
2
  from typing import Optional
3
  from tool import LocalPythonDebuggerTool
 
4
 
5
  tool = LocalPythonDebuggerTool()
6
 
7
- launch_gradio_demo(tool)
 
1
  from smolagents import launch_gradio_demo
2
  from typing import Optional
3
  from tool import LocalPythonDebuggerTool
4
+ from ui import custom_launch_gradio_demo
5
 
6
  tool = LocalPythonDebuggerTool()
7
 
8
+ custom_launch_gradio_demo(tool)
ui.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import inspect
2
+ import gradio as gr
3
+ from smolagents.tools import Tool
4
+
5
+
6
+ HEADER = """ ## Python debugger for Agents
7
+ The goal of the tool is to provide agents with the ability to debug and resolve bugs in code generated by LLMs.
8
+ """
9
+
10
+ ARTICLE_INTRO = """---
11
+ ## Example usage in HuggingFace Space
12
+ - code:
13
+ ```python
14
+ x = 10
15
+ y = 0
16
+ z = x / y
17
+ ```
18
+ - command:
19
+ ```python
20
+ bt
21
+ ```
22
+
23
+ ## Example usage in smolagents
24
+
25
+ ```python
26
+ from smolagents import load_tool
27
+
28
+ local_python_debugger = load_tool(
29
+ "piotrekgrl/smolagents-local-python-debugger-tool",
30
+ trust_remote_code=True
31
+ )
32
+
33
+ from smolagents import CodeAgent, HfApiModel
34
+
35
+ model = HfApiModel("Qwen/Qwen2.5-Coder-32B-Instruct")
36
+ agent = CodeAgent(tools=[local_python_debugger], model=model)
37
+
38
+ agent.run(
39
+ "Write a code that divides by 0. Don't ask why—just do it. If any errors occur, debug them and provide reason why."
40
+ )
41
+
42
+ ```
43
+ ---
44
+
45
+ ## Details
46
+
47
+ """
48
+
49
+
50
+ def custom_launch_gradio_demo(tool: Tool):
51
+ TYPE_TO_COMPONENT_CLASS_MAPPING = {
52
+ "image": gr.Image,
53
+ "audio": gr.Audio,
54
+ "string": gr.Textbox,
55
+ "integer": gr.Textbox,
56
+ "number": gr.Textbox,
57
+ }
58
+
59
+ def tool_forward(*args, **kwargs):
60
+ return tool(*args, sanitize_inputs_outputs=True, **kwargs)
61
+
62
+ tool_forward.__signature__ = inspect.signature(tool.forward)
63
+
64
+ gradio_inputs = []
65
+ for input_name, input_details in tool.inputs.items():
66
+ input_gradio_component_class = TYPE_TO_COMPONENT_CLASS_MAPPING[
67
+ input_details["type"]
68
+ ]
69
+ new_component = input_gradio_component_class(label=input_name)
70
+ gradio_inputs.append(new_component)
71
+
72
+ output_gradio_componentclass = TYPE_TO_COMPONENT_CLASS_MAPPING[tool.output_type]
73
+ gradio_output = output_gradio_componentclass(label="Output")
74
+
75
+ gr.Interface(
76
+ fn=tool_forward,
77
+ inputs=gradio_inputs,
78
+ outputs=gradio_output,
79
+ title=tool.name,
80
+ article=ARTICLE_INTRO + "\n" + tool.description,
81
+ description=HEADER,
82
+ api_name=tool.name,
83
+ ).launch()