Spaces:
Sleeping
Sleeping
fix: pin jinja2 and let HF supervisor launch demo natively
Browse files- app.py +14 -24
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,37 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
-
from fastapi.responses import JSONResponse
|
| 4 |
from app.api.routes import router
|
| 5 |
from app.engine.inference import generate_sql
|
| 6 |
|
| 7 |
-
# 1. ZeroGPU
|
| 8 |
@spaces.GPU(duration=60)
|
| 9 |
def gpu_predict(prompt: str):
|
| 10 |
return generate_sql(prompt, n_candidates=1)
|
| 11 |
|
| 12 |
-
# 2.
|
| 13 |
with gr.Blocks(title="Text-to-SQL API") as demo:
|
| 14 |
-
gr.Markdown("#
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
# 3.
|
| 21 |
demo.app.include_router(router, prefix="/v1")
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
return {"status": "ok"}
|
| 26 |
-
|
| 27 |
-
@demo.app.get("/api-info")
|
| 28 |
-
def api_info():
|
| 29 |
-
return JSONResponse(
|
| 30 |
-
content={
|
| 31 |
-
"docs": "/docs",
|
| 32 |
-
"generate": "/v1/generate"
|
| 33 |
-
}
|
| 34 |
-
)
|
| 35 |
-
|
| 36 |
-
if __name__ == "__main__":
|
| 37 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
|
|
|
| 3 |
from app.api.routes import router
|
| 4 |
from app.engine.inference import generate_sql
|
| 5 |
|
| 6 |
+
# 1. Satisfy ZeroGPU AST scanner
|
| 7 |
@spaces.GPU(duration=60)
|
| 8 |
def gpu_predict(prompt: str):
|
| 9 |
return generate_sql(prompt, n_candidates=1)
|
| 10 |
|
| 11 |
+
# 2. Build a standard visible block (avoids Jinja empty context bug)
|
| 12 |
with gr.Blocks(title="Text-to-SQL API") as demo:
|
| 13 |
+
gr.Markdown("# Text-to-SQL Backend Microservice")
|
| 14 |
+
gr.Markdown("FastAPI Swagger docs are available at [/docs](/docs).")
|
| 15 |
+
|
| 16 |
+
with gr.Row():
|
| 17 |
+
test_in = gr.Textbox(label="Test Prompt", value="[SCHEMA] ... [QUESTION] count users [SQL] ")
|
| 18 |
+
test_out = gr.Textbox(label="Generated SQL Output")
|
| 19 |
+
|
| 20 |
+
run_btn = gr.Button("Run Inference Test")
|
| 21 |
+
run_btn.click(fn=gpu_predict, inputs=test_in, outputs=test_out)
|
| 22 |
|
| 23 |
+
# 3. Mount your FastAPI routes directly onto Gradio's internal Starlette/FastAPI app
|
| 24 |
demo.app.include_router(router, prefix="/v1")
|
| 25 |
|
| 26 |
+
# Notice: NO demo.launch() and NO uvicorn.run().
|
| 27 |
+
# Hugging Face's ZeroGPU supervisor launches the `demo` object automatically.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -4,5 +4,6 @@ pydantic>=2.0.0
|
|
| 4 |
torch
|
| 5 |
transformers
|
| 6 |
gradio==4.44.1
|
|
|
|
| 7 |
huggingface_hub<0.28.0
|
| 8 |
spaces
|
|
|
|
| 4 |
torch
|
| 5 |
transformers
|
| 6 |
gradio==4.44.1
|
| 7 |
+
jinja2<3.1.4
|
| 8 |
huggingface_hub<0.28.0
|
| 9 |
spaces
|