Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
import random
|
4 |
import os
|
@@ -221,62 +221,11 @@ def deploy_button_click(app_name: str, code: str) -> str:
|
|
221 |
if not app_name:
|
222 |
return "Please enter a valid app name."
|
223 |
|
224 |
-
#
|
225 |
-
|
226 |
|
227 |
-
#
|
228 |
-
|
229 |
-
return "Please enter a valid Hugging Face token."
|
230 |
-
|
231 |
-
# Create a new directory for the app
|
232 |
-
os.makedirs(app_name, exist_ok=True)
|
233 |
-
|
234 |
-
# Copy the code to the app directory
|
235 |
-
with open(os.path.join(app_name, 'app.py'), 'w') as f:
|
236 |
-
f.write(code)
|
237 |
-
|
238 |
-
# Create the requirements.txt file
|
239 |
-
with open(os.path.join(app_name, 'requirements.txt'), 'w') as f:
|
240 |
-
f.write("gradio\nhuggingface_hub")
|
241 |
-
|
242 |
-
# Deploy the app to Hugging Face Spaces
|
243 |
-
try:
|
244 |
-
subprocess.run(
|
245 |
-
['huggingface-cli', 'login', '--token', hf_token],
|
246 |
-
check=True,
|
247 |
-
)
|
248 |
-
subprocess.run(
|
249 |
-
['huggingface-cli', 'space', 'create', app_name, '--repo_type', 'spaces', '--private', '--branch', 'main'],
|
250 |
-
check=True,
|
251 |
-
)
|
252 |
-
subprocess.run(
|
253 |
-
['git', 'init'],
|
254 |
-
cwd=app_name,
|
255 |
-
check=True,
|
256 |
-
)
|
257 |
-
subprocess.run(
|
258 |
-
['git', 'add', '.'],
|
259 |
-
cwd=app_name,
|
260 |
-
check=True,
|
261 |
-
)
|
262 |
-
subprocess.run(
|
263 |
-
['git', 'commit', '-m', 'Initial commit'],
|
264 |
-
cwd=app_name,
|
265 |
-
check=True,
|
266 |
-
)
|
267 |
-
subprocess.run(
|
268 |
-
['git', 'remote', 'add', 'origin', hf_hub_url(username='your_username', repo_id=app_name)],
|
269 |
-
cwd=app_name,
|
270 |
-
check=True,
|
271 |
-
)
|
272 |
-
subprocess.run(
|
273 |
-
['git', 'push', '-u', 'origin', 'main'],
|
274 |
-
cwd=app_name,
|
275 |
-
check=True,
|
276 |
-
)
|
277 |
-
return f"Web app '{app_name}' deployed successfully to Hugging Face Spaces!"
|
278 |
-
except subprocess.CalledProcessError as e:
|
279 |
-
return f"Error: {e}"
|
280 |
|
281 |
# Function to handle the "Local Host" button click
|
282 |
def local_host_button_click(app_name: str, code: str) -> str:
|
@@ -288,17 +237,6 @@ def local_host_button_click(app_name: str, code: str) -> str:
|
|
288 |
if not app_name:
|
289 |
return "Please enter a valid app name."
|
290 |
|
291 |
-
# Create a new directory for the app
|
292 |
-
os.makedirs(app_name, exist_ok=True)
|
293 |
-
|
294 |
-
# Copy the code to the app directory
|
295 |
-
with open(os.path.join(app_name, 'app.py'), 'w') as f:
|
296 |
-
f.write(code)
|
297 |
-
|
298 |
-
# Create the requirements.txt file
|
299 |
-
with open(os.path.join(app_name, 'requirements.txt'), 'w') as f:
|
300 |
-
f.write("gradio\nhuggingface_hub")
|
301 |
-
|
302 |
# Start the local server
|
303 |
os.chdir(app_name)
|
304 |
subprocess.Popen(['gradio', 'run', 'app.py', '--share', '--server_port', str(LOCAL_HOST_PORT)])
|
@@ -405,7 +343,6 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
|
405 |
deploy_button = gr.Button("Deploy")
|
406 |
local_host_button = gr.Button("Local Host")
|
407 |
ship_button = gr.Button("Ship")
|
408 |
-
hf_token_input = gr.Textbox(label="Hugging Face Token", placeholder="Enter your Hugging Face token")
|
409 |
|
410 |
# Web App Creation Logic
|
411 |
create_web_app_button.click(
|
@@ -417,7 +354,7 @@ with gr.Blocks(theme='ParityError/Interstellar') as demo:
|
|
417 |
# Deploy the web app
|
418 |
deploy_button.click(
|
419 |
deploy_button_click,
|
420 |
-
inputs=[app_name_input, code_output
|
421 |
outputs=[gr.Textbox(label="Status", interactive=False)],
|
422 |
)
|
423 |
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
import random
|
4 |
import os
|
|
|
221 |
if not app_name:
|
222 |
return "Please enter a valid app name."
|
223 |
|
224 |
+
# Deploy the web app instance
|
225 |
+
# ... (Implement deployment logic here)
|
226 |
|
227 |
+
# Return a success message
|
228 |
+
return f"Web app '{app_name}' deployed successfully!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
|
230 |
# Function to handle the "Local Host" button click
|
231 |
def local_host_button_click(app_name: str, code: str) -> str:
|
|
|
237 |
if not app_name:
|
238 |
return "Please enter a valid app name."
|
239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
# Start the local server
|
241 |
os.chdir(app_name)
|
242 |
subprocess.Popen(['gradio', 'run', 'app.py', '--share', '--server_port', str(LOCAL_HOST_PORT)])
|
|
|
343 |
deploy_button = gr.Button("Deploy")
|
344 |
local_host_button = gr.Button("Local Host")
|
345 |
ship_button = gr.Button("Ship")
|
|
|
346 |
|
347 |
# Web App Creation Logic
|
348 |
create_web_app_button.click(
|
|
|
354 |
# Deploy the web app
|
355 |
deploy_button.click(
|
356 |
deploy_button_click,
|
357 |
+
inputs=[app_name_input, code_output],
|
358 |
outputs=[gr.Textbox(label="Status", interactive=False)],
|
359 |
)
|
360 |
|