Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from parser import parse
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def parse_problem(question:str):
|
| 6 |
+
return parse(question).model_dump()
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
demo = gr.Interface(
|
| 10 |
+
fn=parse_problem,
|
| 11 |
+
inputs=gr.Textbox(
|
| 12 |
+
lines=5,
|
| 13 |
+
label="Problem"
|
| 14 |
+
),
|
| 15 |
+
outputs=gr.JSON(),
|
| 16 |
+
title="Combinatorics Parser",
|
| 17 |
+
description="Semantic parser for combinatorics problems."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
demo.launch()
|
parser.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from schema import ProblemObject
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def parse(question: str):
|
| 5 |
+
|
| 6 |
+
return ProblemObject(
|
| 7 |
+
|
| 8 |
+
schemaVersion="1.0",
|
| 9 |
+
|
| 10 |
+
status="complete",
|
| 11 |
+
|
| 12 |
+
confidence=1.0,
|
| 13 |
+
|
| 14 |
+
domain="combinatorics",
|
| 15 |
+
|
| 16 |
+
problemType="combination",
|
| 17 |
+
|
| 18 |
+
intent="choose",
|
| 19 |
+
|
| 20 |
+
entities={
|
| 21 |
+
"object": "students"
|
| 22 |
+
},
|
| 23 |
+
|
| 24 |
+
parameters={
|
| 25 |
+
"n": 10,
|
| 26 |
+
"r": 3
|
| 27 |
+
},
|
| 28 |
+
|
| 29 |
+
constraints={
|
| 30 |
+
"orderMatters": False
|
| 31 |
+
},
|
| 32 |
+
|
| 33 |
+
missing=[],
|
| 34 |
+
|
| 35 |
+
ambiguities=[],
|
| 36 |
+
|
| 37 |
+
diagnostics=[],
|
| 38 |
+
|
| 39 |
+
metadata={
|
| 40 |
+
"engine": "dummy-parser"
|
| 41 |
+
}
|
| 42 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
fastapi
|
| 3 |
+
uvicorn
|
| 4 |
+
pydantic
|
schema.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional, Dict, List, Any
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class Diagnostic(BaseModel):
|
| 6 |
+
severity: str
|
| 7 |
+
message: str
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class ProblemObject(BaseModel):
|
| 11 |
+
schemaVersion: str
|
| 12 |
+
status: str
|
| 13 |
+
confidence: float
|
| 14 |
+
|
| 15 |
+
domain: Optional[str]
|
| 16 |
+
problemType: Optional[str]
|
| 17 |
+
intent: Optional[str]
|
| 18 |
+
|
| 19 |
+
entities: Dict[str, Any]
|
| 20 |
+
parameters: Dict[str, Any]
|
| 21 |
+
constraints: Dict[str, Any]
|
| 22 |
+
|
| 23 |
+
missing: List[str]
|
| 24 |
+
ambiguities: List[Any]
|
| 25 |
+
diagnostics: List[Diagnostic]
|
| 26 |
+
metadata: Dict[str, Any]
|