thecupcutapk commited on
Commit
e764231
·
verified ·
1 Parent(s): 55248e9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Simple Gradio app for Hugging Face Spaces to display and offer the CapCut article HTML for download.
3
+ Place this file inside: capcutmodapk/app.py
4
+ Make sure you add a requirements.txt with:
5
+ gradio
6
+
7
+ This app will:
8
+ - Load `capcut-article.html` (created earlier) if present
9
+ - Render the HTML inside the Space using gr.HTML
10
+ - Provide a download button (gr.File) for the HTML file
11
+
12
+ """
13
+
14
+ import os
15
+ from pathlib import Path
16
+ import gradio as gr
17
+
18
+ HERE = Path(__file__).parent
19
+ HTML_FILE = HERE / "capcut-article.html"
20
+
21
+ # read the article html if it exists
22
+ if HTML_FILE.exists():
23
+ article_html = HTML_FILE.read_text(encoding="utf-8")
24
+ else:
25
+ article_html = "<h2>CapCut Article Not Found</h2><p>Please add <code>capcut-article.html</code> to this folder.</p>"
26
+
27
+
28
+ def provide_file():
29
+ """Return path to the HTML file so Gradio's File component can serve it for download."""
30
+ if HTML_FILE.exists():
31
+ return str(HTML_FILE.resolve())
32
+ return None
33
+
34
+
35
+ def make_interface():
36
+ with gr.Blocks(title="CapCut Article Viewer") as demo:
37
+ gr.Markdown("# CapCut Article — Viewer & Download")
38
+ gr.Markdown("This Space displays the CapCut article and provides a download link for the HTML file.\n\nIf you want to edit the article, open `capcut-article.html` in the repository and commit your changes.")
39
+
40
+ with gr.Row():
41
+ with gr.Column(scale=3):
42
+ # Render article HTML (safe for Spaces)
43
+ gr.HTML(article_html, elem_id="article-view")
44
+
45
+ with gr.Column(scale=1):
46
+ gr.Markdown("### Download")
47
+ file_output = gr.File(value=provide_file(), label="Download capcut-article.html")
48
+
49
+ gr.Markdown("---")
50
+ gr.Markdown("### Repo structure expected:\n\n```\nthecupcutapk/\n capcutmodapk/\n app.py\n capcut-article.html\n```\n\nIf `capcut-article.html` is missing, add it to the folder and re-run the Space.")
51
+
52
+ gr.Markdown("---\nMade for Hugging Face Spaces — simple, static article viewer.\n")
53
+ return demo
54
+
55
+
56
+ app = make_interface()
57
+
58
+ if __name__ == "__main__":
59
+ # For local testing: python app.py
60
+ app.launch(server_name="0.0.0.0", server_port=7860)