DeepDigest / app.py
ArielKes's picture
app and server code. app sends pdf to server that returns mmd
64cf084
Raw History Blame Contribute Delete
1.19 kB
import gradio as gr
import requests
SERVER_URL = "http://localhost:8000/predict" # your LitServer endpoint
def process_pdf_with_server(pdf_filepath):
if not pdf_filepath:
return "please upload a pdf file."
try:
with open(pdf_filepath, "rb") as f:
files = {"request": f} # "request" matches your LitAPI decode_request
response = requests.post(SERVER_URL, files=files)
if response.status_code == 200:
return response.json().get("markdown_output", "no output received")
else:
return f"server error: {response.status_code} - {response.text}"
except Exception as e:
return f"an error occurred while contacting server: {e}"
iface = gr.Interface(
fn=process_pdf_with_server,
inputs=gr.File(label="Upload your PDF", type="filepath", file_types=[".pdf"]),
outputs=gr.Textbox(label="Markdown output", lines=20),
title="PDF to Markdown with Nougat",
description="This Gradio UI sends PDFs to the backend server for processing with Nougat.",
allow_flagging="never",
)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)