Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,18 +12,18 @@ def generate_files(title="Text Generation Tool", tool_description="This is a too
|
|
| 12 |
|
| 13 |
# Generate readme content
|
| 14 |
readme_content = '''
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
'''.format(title)
|
| 28 |
|
| 29 |
tool_name = title.replace(" ", "_").lower()
|
|
@@ -40,36 +40,39 @@ def generate_files(title="Text Generation Tool", tool_description="This is a too
|
|
| 40 |
tool_config_json = json.dumps(tool_config, indent=4)
|
| 41 |
|
| 42 |
# Generate app.py content
|
| 43 |
-
app_py_content = '''
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
'''.format( tool_name, tool_class, tool_class)
|
| 49 |
|
| 50 |
# Generate requirements.txt content
|
| 51 |
-
requirements_content = '''
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
'''
|
| 56 |
|
| 57 |
# Generate text_generator.py content
|
| 58 |
-
text_generator_py_content = '''
|
|
|
|
| 59 |
from transformers import pipeline
|
| 60 |
class {}(Tool):
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
'''.format(tool_class, tool_name, tool_description)
|
| 74 |
|
| 75 |
# Create a new folder for the tool
|
|
@@ -112,7 +115,7 @@ io = gr.Interface(generate_files,
|
|
| 112 |
label="Titel",
|
| 113 |
info="Initial text",
|
| 114 |
lines=1,
|
| 115 |
-
value="
|
| 116 |
),
|
| 117 |
gr.Textbox(
|
| 118 |
label="Text 2",
|
|
|
|
| 12 |
|
| 13 |
# Generate readme content
|
| 14 |
readme_content = '''
|
| 15 |
+
---
|
| 16 |
+
title: {}
|
| 17 |
+
emoji: 🌖
|
| 18 |
+
colorFrom: blue
|
| 19 |
+
colorTo: blue
|
| 20 |
+
sdk: gradio
|
| 21 |
+
sdk_version: 4.3.0
|
| 22 |
+
app_file: app.py
|
| 23 |
+
pinned: false
|
| 24 |
+
tags:
|
| 25 |
+
- tool
|
| 26 |
+
---
|
| 27 |
'''.format(title)
|
| 28 |
|
| 29 |
tool_name = title.replace(" ", "_").lower()
|
|
|
|
| 40 |
tool_config_json = json.dumps(tool_config, indent=4)
|
| 41 |
|
| 42 |
# Generate app.py content
|
| 43 |
+
app_py_content = '''
|
| 44 |
+
from transformers.tools.base
|
| 45 |
+
from transformers import Tool
|
| 46 |
+
import launch_gradio_demo
|
| 47 |
+
from {} import {}
|
| 48 |
+
launch_gradio_demo({}Tool)
|
| 49 |
'''.format( tool_name, tool_class, tool_class)
|
| 50 |
|
| 51 |
# Generate requirements.txt content
|
| 52 |
+
requirements_content = '''
|
| 53 |
+
transformers>=4.29.0
|
| 54 |
+
# diffusers
|
| 55 |
+
accelerate
|
| 56 |
+
torch
|
| 57 |
'''
|
| 58 |
|
| 59 |
# Generate text_generator.py content
|
| 60 |
+
text_generator_py_content = '''
|
| 61 |
+
import os
|
| 62 |
from transformers import pipeline
|
| 63 |
class {}(Tool):
|
| 64 |
+
name = "{}"
|
| 65 |
+
description = (
|
| 66 |
+
"{}"
|
| 67 |
+
)
|
| 68 |
+
inputs = ["text"]
|
| 69 |
+
outputs = ["text"]
|
| 70 |
+
def __call__(self, prompt: str):
|
| 71 |
+
token = os.environ['hf']
|
| 72 |
+
text_generator = pipeline(model="microsoft/Orca-2-13b", token=token)
|
| 73 |
+
generated_text = text_generator(prompt, max_length=500, num_return_sequences=1, temperature=0.7)
|
| 74 |
+
print(generated_text)
|
| 75 |
+
return generated_text
|
| 76 |
'''.format(tool_class, tool_name, tool_description)
|
| 77 |
|
| 78 |
# Create a new folder for the tool
|
|
|
|
| 115 |
label="Titel",
|
| 116 |
info="Initial text",
|
| 117 |
lines=1,
|
| 118 |
+
value="Cool Tool3",
|
| 119 |
),
|
| 120 |
gr.Textbox(
|
| 121 |
label="Text 2",
|