Spaces:
Sleeping
Sleeping
| # main.py | |
| import os | |
| import uvicorn | |
| # ---- Adjust imports to match a2a-python ---- | |
| # These paths are common in the tutorial; if yours differ, change them accordingly. | |
| from a2a.server.apps import A2AStarletteApplication | |
| from a2a.server.request_handlers import DefaultRequestHandler | |
| from a2a.server.tasks import InMemoryTaskStore | |
| # Example minimal executor | |
| class HelloWorldAgentExecutor: | |
| async def call(self, message: str, **kwargs): | |
| return {"text": f"Hello from A2A on HF Spaces! You said: {message}"} | |
| # Example minimal public AgentCard (adjust fields to your spec) | |
| AGENT_CARD = { | |
| "name": "HF A2A Agent", | |
| "version": "1.0", | |
| "description": "A2A demo running on Hugging Face Spaces", | |
| "endpoints": { | |
| "send": "/message/send", | |
| "stream": "/message/stream" | |
| } | |
| } | |
| def build_app(): | |
| app = A2AStarletteApplication( | |
| agent_card=AGENT_CARD, | |
| http_handler=DefaultRequestHandler( | |
| agent_executor=HelloWorldAgentExecutor(), | |
| task_store=InMemoryTaskStore(), | |
| ), | |
| # extended_agent_card=... # optional | |
| ).build() | |
| return app | |
| if __name__ == "__main__": | |
| port = int(os.getenv("PORT", "7860")) # HF provides PORT | |
| uvicorn.run(build_app(), host="0.0.0.0", port=port) | |