Chris4K commited on
Commit
7f48d07
·
verified ·
1 Parent(s): 2af0df5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import json
2
  import gradio as gr
3
- from transformers import TransformersMeta
4
 
5
  def generate_files(title="Text Generation Tool", emoji="🌖", colorFrom="blue", colorTo="blue",
6
  sdk="gradio", sdk_version="4.3.0", app_file="app.py", pinned=False,
@@ -32,7 +32,6 @@ tags:
32
  # Generate app.py content
33
  app_py_content = '''from transformers.tools.base import launch_gradio_demo
34
  from {} import {}Tool
35
-
36
  launch_gradio_demo({}Tool)
37
  '''.format(tool_name, tool_name.capitalize(), tool_name.capitalize())
38
 
@@ -46,17 +45,13 @@ torch
46
  # Generate text_generator.py content
47
  text_generator_py_content = '''import os
48
  from transformers import pipeline
49
- from transformers import Tool
50
-
51
  class {}Tool(Tool):
52
  name = "{}"
53
  description = (
54
  "{}"
55
  )
56
-
57
  inputs = ["text"]
58
  outputs = ["text"]
59
-
60
  def __call__(self, prompt: str):
61
  token = os.environ['hf']
62
  text_generator = pipeline(model="microsoft/Orca-2-13b", token=token)
@@ -81,22 +76,21 @@ class {}Tool(Tool):
81
  with open("{}.py".format(tool_name), "w") as text_generator_py_file:
82
  text_generator_py_file.write(text_generator_py_content)
83
 
84
- # Create a new space on Hugging Face
85
- space = TransformersMeta.create_space(name=tool_name, description=tool_description)
86
-
87
- # Upload the files to the new space
88
- space.upload_file("README.md")
89
- space.upload_file("tool_config.json")
90
- space.upload_file("app.py")
91
- space.upload_file("requirements.txt")
92
- space.upload_file("{}.py".format(tool_name))
93
 
94
  # Return the generated files for download
95
  return "README.md", "tool_config.json", "app.py", "requirements.txt", "{}.py".format(tool_name)
96
 
97
 
98
  # Define the inputs for the Gradio interface
99
- io = gr.Interface(generate_files,
100
  inputs=["text", "text", "text", "text", "text", "text", "text", "text", "checkbox", "text", "text"],
101
  outputs=["text", "text", "text", "text", "text"])
102
 
 
1
  import json
2
  import gradio as gr
3
+ from transformers import Tool, push_to_hub
4
 
5
  def generate_files(title="Text Generation Tool", emoji="🌖", colorFrom="blue", colorTo="blue",
6
  sdk="gradio", sdk_version="4.3.0", app_file="app.py", pinned=False,
 
32
  # Generate app.py content
33
  app_py_content = '''from transformers.tools.base import launch_gradio_demo
34
  from {} import {}Tool
 
35
  launch_gradio_demo({}Tool)
36
  '''.format(tool_name, tool_name.capitalize(), tool_name.capitalize())
37
 
 
45
  # Generate text_generator.py content
46
  text_generator_py_content = '''import os
47
  from transformers import pipeline
 
 
48
  class {}Tool(Tool):
49
  name = "{}"
50
  description = (
51
  "{}"
52
  )
 
53
  inputs = ["text"]
54
  outputs = ["text"]
 
55
  def __call__(self, prompt: str):
56
  token = os.environ['hf']
57
  text_generator = pipeline(model="microsoft/Orca-2-13b", token=token)
 
76
  with open("{}.py".format(tool_name), "w") as text_generator_py_file:
77
  text_generator_py_file.write(text_generator_py_content)
78
 
79
+ # Upload the files to the Hugging Face Hub
80
+ push_to_hub(
81
+ model_id=tool_name,
82
+ repo_path="./",
83
+ commit_message="Upload {} tool".format(tool_name),
84
+ organization="your_organization", # Replace 'your_organization' with your actual organization
85
+ private=False # Set to True if you want the repository to be private
86
+ )
 
87
 
88
  # Return the generated files for download
89
  return "README.md", "tool_config.json", "app.py", "requirements.txt", "{}.py".format(tool_name)
90
 
91
 
92
  # Define the inputs for the Gradio interface
93
+ io = gr.Interface(generate_files,
94
  inputs=["text", "text", "text", "text", "text", "text", "text", "text", "checkbox", "text", "text"],
95
  outputs=["text", "text", "text", "text", "text"])
96