TestSpace / app.py
AntonyManojXavier's picture
Update app.py
637cb12 verified
Raw History Blame Contribute Delete
1.04 kB
import gradio as gr
from processing import process_file
from models import ModifiedGCN
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import JSONResponse
import uvicorn
app = FastAPI()
def process_file_wrapper(file_path):
status, file = process_file(file_path)
return status, file
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
contents = await file.read()
file_path = "uploaded_file.json"
with open(file_path, "wb") as f:
f.write(contents)
status, processed_file = process_file_wrapper(file_path)
return JSONResponse(content={"status": status, "file": processed_file})
def gradio_interface():
iface = gr.Interface(
fn=process_file_wrapper,
inputs=gr.File(label="Upload your file"),
outputs=[gr.Textbox(label="Status"), gr.File(label="Download the file")]
)
iface.launch(server_name="0.0.0.0", server_port=7860)
if __name__ == "__main__":
gradio_interface()
uvicorn.run(app, host="0.0.0.0", port=7860)