|
import re |
|
import requests |
|
import gradio as gr |
|
|
|
|
|
MODAL_ROOT = "https://dongreanay--repo-to-pdf-converter-web-server.modal.run" |
|
|
|
|
|
|
|
|
|
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/" |
|
payload = {"data": [repo_url], "fn_index": 0} |
|
|
|
resp = requests.post(api, json=payload, timeout=180) |
|
resp.raise_for_status() |
|
|
|
markdown = resp.json()["data"][0] |
|
|
|
|
|
markdown = re.sub(r"\]\(/download/", f"]({MODAL_ROOT}/download/", markdown) |
|
|
|
return markdown |
|
|
|
|
|
|
|
|
|
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__": |
|
|
|
demo.launch() |
|
|