import gradio as gr from fastapi import FastAPI from services.tagging import tag_memory_item, TextIn # Initialize FastAPI app = FastAPI() # Gradio Interface def predict_tags(text: str): result = tag_memory_item(TextIn(text=text)) return result["tags"] # Create Gradio app demo = gr.Interface( fn=predict_tags, inputs=gr.Textbox(label="Input Text"), outputs=gr.JSON(label="Tags"), title="Tagging API", ) # Mount Gradio to FastAPI at root app = gr.mount_gradio_app(app, demo, path="/gradio") # Explicitly add your FastAPI endpoint @app.post("/tags") async def tags_endpoint(data: TextIn): return tag_memory_item(data) @app.get("/") def root(): return {"message": "Welcome! Use /gradio for the UI or POST to /tags for the API."} if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=7860)