m-ric HF staff commited on
Commit
788ee56
1 Parent(s): d0998b2

Upload tool

Browse files
Files changed (4) hide show
  1. app.py +4 -0
  2. requirements.txt +2 -0
  3. tool.py +22 -0
  4. tool_config.json +16 -0
app.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from transformers import launch_gradio_demo
2
+ from tool import SpaceToolWrapper
3
+
4
+ launch_gradio_demo(SpaceToolWrapper)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ agents_package
2
+
tool.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from agents import Tool
2
+
3
+ class SpaceToolWrapper(Tool):
4
+ name = "face_swapper"
5
+ description = """Tool that puts the face shown on the first image on the second image. It taks paths to images as arguments (can be relative path), or PIL images directly."""
6
+ inputs = {"source_file":{"type":"any","description":""},"target_file":{"type":"any","description":""}}
7
+ output_type = "image"
8
+
9
+ def forward(self, *args, **kwargs):
10
+ # Preprocess args and kwargs:
11
+ args = list(args)
12
+ for i, arg in enumerate(args):
13
+ args[i] = self.sanitize_argument_for_prediction(arg)
14
+ for arg_name, arg in kwargs.items():
15
+ kwargs[arg_name] = self.sanitize_argument_for_prediction(arg)
16
+
17
+ output = self.client.predict(*args, api_name=self.api_name, **kwargs)
18
+ if isinstance(output, tuple) or isinstance(output, list):
19
+ return output[
20
+ 0
21
+ ] # Sometime the space also returns the generation seed, in which case the result is at index 0
22
+ return output
tool_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "description": "Tool that puts the face shown on the first image on the second image. It taks paths to images as arguments (can be relative path), or PIL images directly.",
3
+ "inputs": {
4
+ "source_file": {
5
+ "description": "",
6
+ "type": "any"
7
+ },
8
+ "target_file": {
9
+ "description": "",
10
+ "type": "any"
11
+ }
12
+ },
13
+ "name": "face_swapper",
14
+ "output_type": "image",
15
+ "tool_class": "SpaceToolWrapper"
16
+ }