first commit
Browse files- Dockerfile +17 -0
- app.py +84 -0
- eval.py +0 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
RUN apt-get update && apt-get install -y \
|
| 6 |
+
build-essential \
|
| 7 |
+
cmake \
|
| 8 |
+
libnetcdf-dev \
|
| 9 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
+
|
| 11 |
+
COPY . .
|
| 12 |
+
RUN pip install -r requirements.txt
|
| 13 |
+
|
| 14 |
+
EXPOSE 7860
|
| 15 |
+
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
| 16 |
+
|
| 17 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pathlib
|
| 2 |
+
import tempfile
|
| 3 |
+
from typing import BinaryIO, Literal
|
| 4 |
+
import json
|
| 5 |
+
from datasets import Dataset
|
| 6 |
+
|
| 7 |
+
import gradio as gr
|
| 8 |
+
from evaluation import evaluate_problem
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
PROBLEM_TYPES = ["geometrical", "simple_to_build", "mhd_stable"]
|
| 13 |
+
|
| 14 |
+
def evaluate_boundary(
|
| 15 |
+
problem_type: Literal["geometrical", "simple_to_build", "mhd_stable"],
|
| 16 |
+
boundary_file: BinaryIO,
|
| 17 |
+
) -> str:
|
| 18 |
+
file_path = boundary_file.name
|
| 19 |
+
if not file_path:
|
| 20 |
+
return "Error: Uploaded file object does not have a valid file path."
|
| 21 |
+
|
| 22 |
+
path_obj = pathlib.Path(file_path)
|
| 23 |
+
timestamp = datetime.utcnow().isoformat()
|
| 24 |
+
|
| 25 |
+
with (
|
| 26 |
+
path_obj.open("rb") as f_in,
|
| 27 |
+
tempfile.NamedTemporaryFile(delete=False, suffix=".json") as tmp,
|
| 28 |
+
):
|
| 29 |
+
file_content = f_in.read()
|
| 30 |
+
tmp.write(file_content)
|
| 31 |
+
tmp_path = pathlib.Path(tmp.name)
|
| 32 |
+
try:
|
| 33 |
+
result = evaluate_problem(problem_type, str(tmp_path))
|
| 34 |
+
output = str(result)
|
| 35 |
+
except Exception as e:
|
| 36 |
+
output = f"Error during evaluation:\n{e}"
|
| 37 |
+
finally:
|
| 38 |
+
tmp_path.unlink()
|
| 39 |
+
|
| 40 |
+
save_to_dataset(problem_type, file_content, timestamp, output)
|
| 41 |
+
return output
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def save_to_dataset(problem_type, file_content, timestamp, result):
|
| 45 |
+
# Example: convert to one-row dataframe
|
| 46 |
+
record = {
|
| 47 |
+
"submission_time": timestamp,
|
| 48 |
+
"problem_type": problem_type,
|
| 49 |
+
"boundary_json": file_content.decode("utf-8"), # Or store file path or URL
|
| 50 |
+
"result": result,
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
# If this is the first entry, create dataset
|
| 54 |
+
dataset_file = "local_dataset.jsonl"
|
| 55 |
+
with open(dataset_file, "a") as f:
|
| 56 |
+
f.write(json.dumps(record) + "\n")
|
| 57 |
+
|
| 58 |
+
def gradio_interface() -> gr.Blocks:
|
| 59 |
+
with gr.Blocks() as demo:
|
| 60 |
+
gr.Markdown(
|
| 61 |
+
"""
|
| 62 |
+
# Plasma Boundary Evaluation App
|
| 63 |
+
Upload your plasma boundary JSON and select the problem type to get your score.
|
| 64 |
+
"""
|
| 65 |
+
)
|
| 66 |
+
with gr.Row():
|
| 67 |
+
problem_type = gr.Dropdown(
|
| 68 |
+
PROBLEM_TYPES, label="Problem Type", value="geometrical"
|
| 69 |
+
)
|
| 70 |
+
boundary_file = gr.File(label="Boundary JSON File (.json)")
|
| 71 |
+
|
| 72 |
+
boundary_file
|
| 73 |
+
output = gr.Textbox(label="Evaluation Result", lines=10)
|
| 74 |
+
submit_btn = gr.Button("Evaluate")
|
| 75 |
+
submit_btn.click(
|
| 76 |
+
evaluate_boundary,
|
| 77 |
+
inputs=[problem_type, boundary_file],
|
| 78 |
+
outputs=output,
|
| 79 |
+
)
|
| 80 |
+
return demo
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
gradio_interface().launch()
|
eval.py
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
constellaration==0.2.1
|
| 2 |
+
gradio
|
| 3 |
+
datasets
|