Download app.py from Olserra/xmem: direct link, hf CLI and curl.
- Browser
- Download file 865 Bytes
-
https://huggingface.co/spaces/Olserra/xmem/resolve/main/app.py
- Command line
-
hf download hf://spaces/Olserra/xmem/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Olserra/xmem/resolve/main/app.py
865 Bytes
| 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 | |
| async def tags_endpoint(data: TextIn): | |
| return tag_memory_item(data) | |
| 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) | |