DrNerd's picture
Initial working proxy Space
38b59a2
import re
import requests
import gradio as gr
# πŸ”— REPLACE with your own Modal endpoint (no trailing slash)
MODAL_ROOT = "https://dongreanay--repo-to-pdf-converter-web-server.modal.run"
# ------------------------------------------------------------------
# Helper: forward the repo URL to Modal and return rewritten markdown
# ------------------------------------------------------------------
def proxy(repo_url: str) -> str:
"""
Sends the GitHub URL to the Modal-hosted Gradio app and returns
its markdown response, but with /download links rewritten to
absolute Modal URLs so the browser can fetch the PDF correctly.
"""
api = f"{MODAL_ROOT}/api/predict/" # Gradio REST endpoint
payload = {"data": [repo_url], "fn_index": 0}
resp = requests.post(api, json=payload, timeout=180)
resp.raise_for_status()
markdown = resp.json()["data"][0] # original markdown
# Rewrite `[...]( /download/filename )` β†’ `[...]( MODAL_ROOT/download/filename )`
markdown = re.sub(r"\]\(/download/", f"]({MODAL_ROOT}/download/", markdown)
return markdown
# ------------------------------------------------------------------
# Gradio UI (thin proxy)
# ------------------------------------------------------------------
demo = gr.Interface(
fn=proxy,
inputs=gr.Textbox(label="GitHub repository URL",
placeholder="https://github.com/owner/repo"),
outputs=gr.Markdown(),
title="GitHub β†’ PDF Converter (Modal backend)",
description="Thin proxy that forwards requests to a Modal-hosted Gradio app.",
examples=[["https://github.com/gradio-app/gradio"]],
)
if __name__ == "__main__":
# For local testing; on a Hugging Face Space, the platform calls launch()
demo.launch()