dwb2023 commited on
Commit
8b2bba8
·
verified ·
1 Parent(s): 6ecf0b3

tool template

Browse files
Files changed (1) hide show
  1. huggingface_spaces_tool_template.md +96 -0
huggingface_spaces_tool_template.md ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Hugging Face Spaces Tool Template for Agents
2
+
3
+ - a quick tribute to [Aymeric](https://huggingface.co/m-ric) for this simple but effective exapmle of how to build and serve agents using Hugging Face spaces
4
+ - check out the documentation here for more information on the transformers implementation of the [Agent Class](https://huggingface.co/docs/transformers/main_classes/agent)
5
+ - capturing the entire repo so that the overall structure and content of the repo is clear
6
+
7
+ ### File: README.md
8
+ **Type:** txt
9
+ **Size:** 247 bytes
10
+ **Created:** 2025-01-22 19:08:45 UTC
11
+ **Modified:** 2025-01-22 19:08:45 UTC
12
+ #### Content:
13
+ ```
14
+ ---
15
+ title: Text To Image
16
+ emoji: 👀
17
+ colorFrom: blue
18
+ colorTo: indigo
19
+ sdk: gradio
20
+ sdk_version: 4.29.0
21
+ app_file: app.py
22
+ pinned: false
23
+ tags:
24
+ - tool
25
+ ---
26
+
27
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
28
+
29
+ ```
30
+
31
+ ### File: app.py
32
+ **Type:** python
33
+ **Size:** 114 bytes
34
+ **Created:** 2025-01-22 19:08:45 UTC
35
+ **Modified:** 2025-01-22 19:08:45 UTC
36
+ #### Content:
37
+ ```
38
+ from transformers import launch_gradio_demo
39
+ from tool import TextToImageTool
40
+
41
+ launch_gradio_demo(TextToImageTool)
42
+
43
+ ```
44
+
45
+ ### File: requirements.txt
46
+ **Type:** txt
47
+ **Size:** 26 bytes
48
+ **Created:** 2025-01-22 19:08:45 UTC
49
+ **Modified:** 2025-01-22 19:08:45 UTC
50
+ #### Content:
51
+ ```
52
+ huggingface_hub
53
+ smolagents
54
+ ```
55
+
56
+ ### File: tool.py
57
+ **Type:** python
58
+ **Size:** 635 bytes
59
+ **Created:** 2025-01-22 19:08:45 UTC
60
+ **Modified:** 2025-01-22 19:08:45 UTC
61
+ #### Content:
62
+ ```
63
+ from smolagents import Tool
64
+ from huggingface_hub import InferenceClient
65
+
66
+
67
+ class TextToImageTool(Tool):
68
+ description = "This tool creates an image according to a prompt, which is a text description."
69
+ name = "image_generator"
70
+ inputs = {"prompt": {"type": "string", "description": "The image generator prompt. Don't hesitate to add details in the prompt to make the image look better, like 'high-res, photorealistic', etc."}}
71
+ output_type = "image"
72
+ model_sdxl = "black-forest-labs/FLUX.1-schnell"
73
+ client = InferenceClient(model_sdxl)
74
+
75
+
76
+ def forward(self, prompt):
77
+ return self.client.text_to_image(prompt)
78
+
79
+ ```
80
+
81
+ ### File: tool_config.json
82
+ **Type:** json
83
+ **Size:** 414 bytes
84
+ **Created:** 2025-01-22 19:08:45 UTC
85
+ **Modified:** 2025-01-22 19:08:45 UTC
86
+ #### Content:
87
+ ```
88
+ {
89
+ "description": "This is a tool that creates an image according to a prompt, which is a text description.",
90
+ "inputs": "{'prompt': {'type': 'string', 'description': \"The image generator prompt. Don't hesitate to add details in the prompt to make the image look better, like 'high-res, photorealistic', etc.\"}}",
91
+ "name": "image_generator",
92
+ "output_type": "image",
93
+ "tool_class": "tool.TextToImageTool"
94
+ }
95
+
96
+ ```