Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -50,9 +50,14 @@ def upload_protocol_file(filepath: str) -> str:
|
|
| 50 |
|
| 51 |
def send_message(text, history):
|
| 52 |
text = (text or "").strip()
|
|
|
|
|
|
|
| 53 |
if not text:
|
| 54 |
return history
|
| 55 |
|
|
|
|
|
|
|
|
|
|
| 56 |
fd, path = tempfile.mkstemp(prefix="protocol_", suffix=".py")
|
| 57 |
try:
|
| 58 |
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
@@ -64,14 +69,18 @@ def send_message(text, history):
|
|
| 64 |
except OSError:
|
| 65 |
pass
|
| 66 |
|
| 67 |
-
|
|
|
|
| 68 |
return history
|
| 69 |
|
| 70 |
with gr.Blocks() as app:
|
| 71 |
gr.Markdown("## Opentrons Protocol Analyzer")
|
| 72 |
textbox = gr.Textbox(lines=12, label="Paste protocol Python code")
|
| 73 |
send_button = gr.Button(value="Analyze")
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
| 75 |
clear_button = gr.ClearButton([textbox, chatbot])
|
| 76 |
|
| 77 |
send_button.click(send_message, [textbox, chatbot], [chatbot])
|
|
|
|
| 50 |
|
| 51 |
def send_message(text, history):
|
| 52 |
text = (text or "").strip()
|
| 53 |
+
history = history or []
|
| 54 |
+
|
| 55 |
if not text:
|
| 56 |
return history
|
| 57 |
|
| 58 |
+
# user message
|
| 59 |
+
history.append({"role": "user", "content": text})
|
| 60 |
+
|
| 61 |
fd, path = tempfile.mkstemp(prefix="protocol_", suffix=".py")
|
| 62 |
try:
|
| 63 |
with os.fdopen(fd, "w", encoding="utf-8") as f:
|
|
|
|
| 69 |
except OSError:
|
| 70 |
pass
|
| 71 |
|
| 72 |
+
# assistant message
|
| 73 |
+
history.append({"role": "assistant", "content": result})
|
| 74 |
return history
|
| 75 |
|
| 76 |
with gr.Blocks() as app:
|
| 77 |
gr.Markdown("## Opentrons Protocol Analyzer")
|
| 78 |
textbox = gr.Textbox(lines=12, label="Paste protocol Python code")
|
| 79 |
send_button = gr.Button(value="Analyze")
|
| 80 |
+
|
| 81 |
+
# 旧Gradioでも動きやすい:余計な引数を渡さない
|
| 82 |
+
chatbot = gr.Chatbot(label="Results")
|
| 83 |
+
|
| 84 |
clear_button = gr.ClearButton([textbox, chatbot])
|
| 85 |
|
| 86 |
send_button.click(send_message, [textbox, chatbot], [chatbot])
|