Vo Hoang Minh commited on
Commit ·
47c696c
1
Parent(s): 35449b8
- .gitignore +2 -1
- dockerbox/render/Dockerfile +10 -0
- pkg/upload_run.py +26 -6
- requirements.txt +1 -1
.gitignore
CHANGED
|
@@ -5,4 +5,5 @@
|
|
| 5 |
|
| 6 |
.DS_Store
|
| 7 |
|
| 8 |
-
tests/
|
|
|
|
|
|
| 5 |
|
| 6 |
.DS_Store
|
| 7 |
|
| 8 |
+
tests/
|
| 9 |
+
node_modules/
|
dockerbox/render/Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.14-rc-slim
|
| 2 |
+
|
| 3 |
+
RUN apt-get update && \
|
| 4 |
+
apt-get install -y wget unzip ffmpeg fonts-nanum && \
|
| 5 |
+
rm -rf /var/lib/apt/lists/*
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
|
| 10 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
pkg/upload_run.py
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
domain = "https://minhvh-toolkit.hf.space/file="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
return "\n".join(
|
| 8 |
|
| 9 |
|
| 10 |
|
|
@@ -12,14 +32,14 @@ def run_upload(files):
|
|
| 12 |
with gr.Blocks(title="File Upload Tool") as demo:
|
| 13 |
gr.Markdown("# Upload Files and Get Links")
|
| 14 |
|
| 15 |
-
files_input = gr.
|
| 16 |
output_code = gr.Code(label="Links", interactive=False, language="markdown")
|
| 17 |
|
| 18 |
files_input.change(
|
| 19 |
-
fn=
|
| 20 |
inputs=files_input,
|
| 21 |
outputs=output_code
|
| 22 |
)
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
| 25 |
-
demo.launch(show_error=True)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
import time, random, string
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
def ulid():
|
| 7 |
+
timestamp = int(time.time())
|
| 8 |
+
rand = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
|
| 9 |
+
return f"{timestamp}{rand}"
|
| 10 |
+
|
| 11 |
+
def upload(file):
|
| 12 |
+
|
| 13 |
+
if not file:
|
| 14 |
+
return "No file uploaded."
|
| 15 |
+
|
| 16 |
domain = "https://minhvh-toolkit.hf.space/file="
|
| 17 |
+
# domain = "http://localhost:7860/file="
|
| 18 |
+
|
| 19 |
+
links = []
|
| 20 |
+
ext = os.path.splitext(file.name)[1]
|
| 21 |
+
name = '/tmp/' + ulid() + ext
|
| 22 |
+
|
| 23 |
+
shutil.copy(file.name, name)
|
| 24 |
+
|
| 25 |
+
links.append(f"{domain}{name}")
|
| 26 |
|
| 27 |
+
return "\n".join(links)
|
| 28 |
|
| 29 |
|
| 30 |
|
|
|
|
| 32 |
with gr.Blocks(title="File Upload Tool") as demo:
|
| 33 |
gr.Markdown("# Upload Files and Get Links")
|
| 34 |
|
| 35 |
+
files_input = gr.File(label="Files")
|
| 36 |
output_code = gr.Code(label="Links", interactive=False, language="markdown")
|
| 37 |
|
| 38 |
files_input.change(
|
| 39 |
+
fn=upload,
|
| 40 |
inputs=files_input,
|
| 41 |
outputs=output_code
|
| 42 |
)
|
| 43 |
|
| 44 |
if __name__ == "__main__":
|
| 45 |
+
demo.launch(show_error=True,)
|
requirements.txt
CHANGED
|
@@ -12,4 +12,4 @@ nanoid
|
|
| 12 |
gdown
|
| 13 |
cachetools
|
| 14 |
pysubs2
|
| 15 |
-
|
|
|
|
| 12 |
gdown
|
| 13 |
cachetools
|
| 14 |
pysubs2
|
| 15 |
+
fire
|