Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
|
5 |
+
def generate_secrets(domain):
|
6 |
+
# Set Mastodon directory
|
7 |
+
mastodon_dir = "/app/mastodon"
|
8 |
+
os.chdir(mastodon_dir)
|
9 |
+
|
10 |
+
# Generate secrets using Mastodon’s rake tasks
|
11 |
+
secret_key_base = subprocess.check_output(
|
12 |
+
["/root/.rbenv/shims/bundle", "exec", "rake", "secret"],
|
13 |
+
env={"RAILS_ENV": "development"}
|
14 |
+
).decode().strip()
|
15 |
+
|
16 |
+
otp_secret = subprocess.check_output(
|
17 |
+
["/root/.rbenv/shims/bundle", "exec", "rake", "secret"],
|
18 |
+
env={"RAILS_ENV": "development"}
|
19 |
+
).decode().strip()
|
20 |
+
|
21 |
+
vapid_keys = subprocess.check_output(
|
22 |
+
["/root/.rbenv/shims/bundle", "exec", "rake", "mastodon:webpush:generate_vapid_key"],
|
23 |
+
env={"RAILS_ENV": "development"}
|
24 |
+
).decode().strip().split("\n")
|
25 |
+
vapid_private_key = next(line.split("=", 1)[1].strip() for line in vapid_keys if "VAPID_PRIVATE_KEY" in line)
|
26 |
+
vapid_public_key = next(line.split("=", 1)[1].strip() for line in vapid_keys if "VAPID_PUBLIC_KEY" in line)
|
27 |
+
|
28 |
+
# Return formatted output
|
29 |
+
output = {
|
30 |
+
"LOCAL_DOMAIN": domain or "your-space-name.hf.space",
|
31 |
+
"SECRET_KEY_BASE": secret_key_base,
|
32 |
+
"OTP_SECRET": otp_secret,
|
33 |
+
"VAPID_PRIVATE_KEY": vapid_private_key,
|
34 |
+
"VAPID_PUBLIC_KEY": vapid_public_key,
|
35 |
+
"RAILS_SERVE_STATIC_FILES": "true"
|
36 |
+
}
|
37 |
+
return "\n".join(f"{k}: {v}" for k, v in output.items())
|
38 |
+
|
39 |
+
# Gradio interface
|
40 |
+
with gr.Blocks(title="Mastodon Secrets Generator") as demo:
|
41 |
+
gr.Markdown("# Mastodon Secrets Generator")
|
42 |
+
gr.Markdown("Enter your domain (or leave blank for default) and generate secrets for your Mastodon Space.")
|
43 |
+
|
44 |
+
domain_input = gr.Textbox(label="Domain (optional)", placeholder="e.g., your-space-name.hf.space")
|
45 |
+
generate_btn = gr.Button("Generate Secrets")
|
46 |
+
output_text = gr.Textbox(label="Secrets (Copy/Paste these into Hugging Face Spaces Secrets)", lines=10)
|
47 |
+
|
48 |
+
generate_btn.click(
|
49 |
+
fn=generate_secrets,
|
50 |
+
inputs=domain_input,
|
51 |
+
outputs=output_text
|
52 |
+
)
|
53 |
+
|
54 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|