import os import sys import time import signal import io from fastapi import FastAPI, Request, status, Form, UploadFile from fastapi.staticfiles import StaticFiles from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel, Field from fastapi.exceptions import RequestValidationError from fastapi.responses import JSONResponse import fn import gradio as gr from app import demo app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=['*'], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) gr.mount_gradio_app(app, demo, path="/gradio") @app.post("/run") async def api_run(text: str): try: text, results = fn.run(text) return {"text": text, "results": results} except Exception as e: return {"error": str(e)} @app.post("/ddg") async def api_ddg(text: str): try: results = fn.ddg(text) return {"results": results} except Exception as e: return {"error": str(e)} @app.post("/bs4") async def api_bs4(url: str): try: text = fn.bs4(url) return {"text": text} except Exception as e: return {"error": str(e)}