Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,31 @@
|
|
| 1 |
-
import
|
| 2 |
-
from flask import Flask, request, redirect, render_template
|
| 3 |
from huggingface_hub import HfApi
|
| 4 |
|
| 5 |
-
app = Flask(__name__)
|
| 6 |
api = HfApi()
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
path_in_repo=file.filename,
|
| 19 |
-
repo_id=repo_id,
|
| 20 |
-
revision=revision,
|
| 21 |
-
create_pr=True,
|
| 22 |
-
)
|
| 23 |
-
return f'File {file.filename} uploaded successfully to {repo_id}'
|
| 24 |
-
except Exception as e:
|
| 25 |
-
return str(e)
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
|
| 30 |
-
app.run(debug=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
|
|
|
|
| 4 |
api = HfApi()
|
| 5 |
|
| 6 |
+
def upload_file(file, repo_id, revision):
|
| 7 |
+
try:
|
| 8 |
+
api.upload_file(
|
| 9 |
+
path_or_file=file,
|
| 10 |
+
path_in_repo=file.name,
|
| 11 |
+
repo_id=repo_id,
|
| 12 |
+
revision=revision,
|
| 13 |
+
create_pr=True,
|
| 14 |
+
)
|
| 15 |
+
return f'File {file.name} uploaded successfully to {repo_id}'
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return str(e)
|
| 18 |
|
| 19 |
+
file_input = gr.inputs.File(label="File")
|
| 20 |
+
repo_id_input = gr.inputs.Textbox(label="Repository ID")
|
| 21 |
+
revision_input = gr.inputs.Textbox(label="Revision")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=upload_file,
|
| 25 |
+
inputs=[file_input, repo_id_input, revision_input],
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="Upload File to Hugging Face",
|
| 28 |
+
description="Upload a file to a Hugging Face repository.",
|
| 29 |
+
)
|
| 30 |
|
| 31 |
+
iface.launch()
|
|
|