Spaces:
Running
Running
KaiWu commited on
Commit ·
2aa101f
1
Parent(s): 24f6cf3
refactor(app): 移除 Gradio feedback 采集模块
Browse files- 删除 write_feedback / submit_feedback 函数与对应 UI 组件(Radio、Textbox、Button、Status)
- 精简 submit_message / reset_session 返回值数量,移除 feedback 相关占位
- 组件输出列表同步瘦身
app.py
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
-
import json
|
| 2 |
import os
|
| 3 |
import shutil
|
| 4 |
-
from datetime import datetime
|
| 5 |
from pathlib import Path
|
| 6 |
from uuid import uuid4
|
| 7 |
|
|
@@ -66,35 +64,13 @@ def format_status(result: dict) -> str:
|
|
| 66 |
]).strip()
|
| 67 |
|
| 68 |
|
| 69 |
-
def write_feedback(state: dict, rating: str, comment: str) -> Path:
|
| 70 |
-
payload = state.get("latest_tool_payload") or {}
|
| 71 |
-
feedback_dir = ARTIFACT_ROOT / "feedback"
|
| 72 |
-
feedback_dir.mkdir(parents=True, exist_ok=True)
|
| 73 |
-
feedback_path = feedback_dir / "feedback.jsonl"
|
| 74 |
-
|
| 75 |
-
record = {
|
| 76 |
-
"timestamp": datetime.now().astimezone().isoformat(timespec="seconds"),
|
| 77 |
-
"session_id": state.get("session_id"),
|
| 78 |
-
"run_id": payload.get("run_id"),
|
| 79 |
-
"rating": rating,
|
| 80 |
-
"comment": comment.strip(),
|
| 81 |
-
"output_path": payload.get("output_path"),
|
| 82 |
-
"manifest_path": payload.get("manifest_path"),
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
-
with feedback_path.open("a", encoding="utf-8") as handle:
|
| 86 |
-
handle.write(json.dumps(record, ensure_ascii=False) + "\n")
|
| 87 |
-
|
| 88 |
-
return feedback_path
|
| 89 |
-
|
| 90 |
-
|
| 91 |
def submit_message(message, state):
|
| 92 |
state = state or new_session_state()
|
| 93 |
text, image_path = parse_user_message(message)
|
| 94 |
uploaded_image = copy_uploaded_image(image_path, state["session_id"])
|
| 95 |
|
| 96 |
if not text and not uploaded_image:
|
| 97 |
-
return state["chat_messages"], state, None, None, "Enter a message or upload an image.", {"text": "", "files": []}
|
| 98 |
|
| 99 |
display_text = text or "Generate a 3D model from the uploaded image."
|
| 100 |
if uploaded_image:
|
|
@@ -121,30 +97,15 @@ def submit_message(message, state):
|
|
| 121 |
result.get("download_path"),
|
| 122 |
status,
|
| 123 |
{"text": "", "files": []},
|
| 124 |
-
None,
|
| 125 |
-
"",
|
| 126 |
-
"",
|
| 127 |
)
|
| 128 |
except Exception as exc:
|
| 129 |
state["chat_messages"].append({"role": "assistant", "content": f"Failed: {exc}"})
|
| 130 |
-
return state["chat_messages"], state, None, None, f"Failed: `{exc}`", {"text": "", "files": []}
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
def submit_feedback(rating, comment, state):
|
| 134 |
-
state = state or new_session_state()
|
| 135 |
-
payload = state.get("latest_tool_payload") or {}
|
| 136 |
-
if not payload.get("run_id"):
|
| 137 |
-
return "Generate a model before submitting feedback.", comment or ""
|
| 138 |
-
if not rating:
|
| 139 |
-
return "Choose satisfied or unsatisfied before submitting feedback.", comment or ""
|
| 140 |
-
|
| 141 |
-
feedback_path = write_feedback(state, rating, comment or "")
|
| 142 |
-
return f"Feedback saved to `{feedback_path}`.", ""
|
| 143 |
|
| 144 |
|
| 145 |
def reset_session():
|
| 146 |
state = new_session_state()
|
| 147 |
-
return [], state, None, None, "New session started.", {"text": "", "files": []}
|
| 148 |
|
| 149 |
|
| 150 |
with gr.Blocks(title="ForgeCAD", fill_height=True) as demo:
|
|
@@ -172,18 +133,6 @@ with gr.Blocks(title="ForgeCAD", fill_height=True) as demo:
|
|
| 172 |
preview = gr.Model3D(label="Model Preview", height=560)
|
| 173 |
download = gr.File(label="Download Latest Model")
|
| 174 |
status = gr.Markdown("No model generated yet.")
|
| 175 |
-
gr.Markdown("### Feedback")
|
| 176 |
-
feedback_rating = gr.Radio(
|
| 177 |
-
choices=["满意", "不满意"],
|
| 178 |
-
label="How was this result?",
|
| 179 |
-
)
|
| 180 |
-
feedback_comment = gr.Textbox(
|
| 181 |
-
label="Optional notes",
|
| 182 |
-
placeholder="What worked, what failed, or what you wanted instead.",
|
| 183 |
-
lines=3,
|
| 184 |
-
)
|
| 185 |
-
feedback_submit = gr.Button("Submit Feedback")
|
| 186 |
-
feedback_status = gr.Markdown("")
|
| 187 |
|
| 188 |
composer.submit(
|
| 189 |
submit_message,
|
|
@@ -195,9 +144,6 @@ with gr.Blocks(title="ForgeCAD", fill_height=True) as demo:
|
|
| 195 |
download,
|
| 196 |
status,
|
| 197 |
composer,
|
| 198 |
-
feedback_rating,
|
| 199 |
-
feedback_comment,
|
| 200 |
-
feedback_status,
|
| 201 |
],
|
| 202 |
)
|
| 203 |
clear.click(
|
|
@@ -209,16 +155,8 @@ with gr.Blocks(title="ForgeCAD", fill_height=True) as demo:
|
|
| 209 |
download,
|
| 210 |
status,
|
| 211 |
composer,
|
| 212 |
-
feedback_rating,
|
| 213 |
-
feedback_comment,
|
| 214 |
-
feedback_status,
|
| 215 |
],
|
| 216 |
)
|
| 217 |
-
feedback_submit.click(
|
| 218 |
-
submit_feedback,
|
| 219 |
-
inputs=[feedback_rating, feedback_comment, state],
|
| 220 |
-
outputs=[feedback_status, feedback_comment],
|
| 221 |
-
)
|
| 222 |
|
| 223 |
|
| 224 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import shutil
|
|
|
|
| 3 |
from pathlib import Path
|
| 4 |
from uuid import uuid4
|
| 5 |
|
|
|
|
| 64 |
]).strip()
|
| 65 |
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
def submit_message(message, state):
|
| 68 |
state = state or new_session_state()
|
| 69 |
text, image_path = parse_user_message(message)
|
| 70 |
uploaded_image = copy_uploaded_image(image_path, state["session_id"])
|
| 71 |
|
| 72 |
if not text and not uploaded_image:
|
| 73 |
+
return state["chat_messages"], state, None, None, "Enter a message or upload an image.", {"text": "", "files": []}
|
| 74 |
|
| 75 |
display_text = text or "Generate a 3D model from the uploaded image."
|
| 76 |
if uploaded_image:
|
|
|
|
| 97 |
result.get("download_path"),
|
| 98 |
status,
|
| 99 |
{"text": "", "files": []},
|
|
|
|
|
|
|
|
|
|
| 100 |
)
|
| 101 |
except Exception as exc:
|
| 102 |
state["chat_messages"].append({"role": "assistant", "content": f"Failed: {exc}"})
|
| 103 |
+
return state["chat_messages"], state, None, None, f"Failed: `{exc}`", {"text": "", "files": []}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
def reset_session():
|
| 107 |
state = new_session_state()
|
| 108 |
+
return [], state, None, None, "New session started.", {"text": "", "files": []}
|
| 109 |
|
| 110 |
|
| 111 |
with gr.Blocks(title="ForgeCAD", fill_height=True) as demo:
|
|
|
|
| 133 |
preview = gr.Model3D(label="Model Preview", height=560)
|
| 134 |
download = gr.File(label="Download Latest Model")
|
| 135 |
status = gr.Markdown("No model generated yet.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
composer.submit(
|
| 138 |
submit_message,
|
|
|
|
| 144 |
download,
|
| 145 |
status,
|
| 146 |
composer,
|
|
|
|
|
|
|
|
|
|
| 147 |
],
|
| 148 |
)
|
| 149 |
clear.click(
|
|
|
|
| 155 |
download,
|
| 156 |
status,
|
| 157 |
composer,
|
|
|
|
|
|
|
|
|
|
| 158 |
],
|
| 159 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
if __name__ == "__main__":
|