Spaces:
Sleeping
Sleeping
Download api/explain.py from RoxieRoller/H-script-AI: direct link, hf CLI and curl.
- Browser
- Download file 989 Bytes
-
https://huggingface.co/spaces/RoxieRoller/H-script-AI/resolve/main/api/explain.py
- Command line
-
hf download hf://spaces/RoxieRoller/H-script-AI/api/explain.py
-
curl -L -o explain.py https://huggingface.co/spaces/RoxieRoller/H-script-AI/resolve/main/api/explain.py
989 Bytes
| """ | |
| POST /ai/explain | |
| Explain selected H-Script code in simple Hinglish. | |
| """ | |
| from fastapi import APIRouter | |
| from pydantic import BaseModel | |
| from core.gemini_client import ask_gemini | |
| router = APIRouter() | |
| class ExplainRequest(BaseModel): | |
| code: str | |
| selection: str | None = None # optional — explain just selected text | |
| class ExplainResponse(BaseModel): | |
| explanation: str | |
| async def explain_code(body: ExplainRequest): | |
| target = body.selection or body.code | |
| prompt = f""" | |
| The user wants a simple explanation of this H-Script code. | |
| Explain it line by line in simple Hinglish — like you're a friendly tutor | |
| talking to a beginner. Use emojis and keep it fun. | |
| Code to explain: | |
| ``` | |
| {target} | |
| ``` | |
| Give a clear, friendly explanation. Mention what each part does. | |
| If there's a bug or potential issue, point it out gently. | |
| """ | |
| explanation = await ask_gemini(prompt) | |
| return ExplainResponse(explanation=explanation) | |