Spaces:
Running
Running
File size: 1,187 Bytes
64cf084 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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)
|