DrNerd commited on
Commit
38b59a2
Β·
1 Parent(s): 8884ea3

Initial working proxy Space

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import requests
3
+ import gradio as gr
4
+
5
+ # πŸ”— REPLACE with your own Modal endpoint (no trailing slash)
6
+ MODAL_ROOT = "https://dongreanay--repo-to-pdf-converter-web-server.modal.run"
7
+
8
+ # ------------------------------------------------------------------
9
+ # Helper: forward the repo URL to Modal and return rewritten markdown
10
+ # ------------------------------------------------------------------
11
+ def proxy(repo_url: str) -> str:
12
+ """
13
+ Sends the GitHub URL to the Modal-hosted Gradio app and returns
14
+ its markdown response, but with /download links rewritten to
15
+ absolute Modal URLs so the browser can fetch the PDF correctly.
16
+ """
17
+ api = f"{MODAL_ROOT}/api/predict/" # Gradio REST endpoint
18
+ payload = {"data": [repo_url], "fn_index": 0}
19
+
20
+ resp = requests.post(api, json=payload, timeout=180)
21
+ resp.raise_for_status()
22
+
23
+ markdown = resp.json()["data"][0] # original markdown
24
+
25
+ # Rewrite `[...]( /download/filename )` β†’ `[...]( MODAL_ROOT/download/filename )`
26
+ markdown = re.sub(r"\]\(/download/", f"]({MODAL_ROOT}/download/", markdown)
27
+
28
+ return markdown
29
+
30
+ # ------------------------------------------------------------------
31
+ # Gradio UI (thin proxy)
32
+ # ------------------------------------------------------------------
33
+ demo = gr.Interface(
34
+ fn=proxy,
35
+ inputs=gr.Textbox(label="GitHub repository URL",
36
+ placeholder="https://github.com/owner/repo"),
37
+ outputs=gr.Markdown(),
38
+ title="GitHub β†’ PDF Converter (Modal backend)",
39
+ description="Thin proxy that forwards requests to a Modal-hosted Gradio app.",
40
+ examples=[["https://github.com/gradio-app/gradio"]],
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ # For local testing; on a Hugging Face Space, the platform calls launch()
45
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio==4.44.0
2
+ requests