Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# app.py
|
| 2 |
-
# @title Beer Game Final Version (v4.
|
| 3 |
|
| 4 |
# -----------------------------------------------------------------------------
|
| 5 |
# 1. Import Libraries
|
|
@@ -22,7 +22,6 @@ from huggingface_hub import HfApi
|
|
| 22 |
# -----------------------------------------------------------------------------
|
| 23 |
st.set_page_config(page_title="Beer Game: Human-AI Collaboration", layout="wide")
|
| 24 |
|
| 25 |
-
|
| 26 |
# -----------------------------------------------------------------------------
|
| 27 |
# 2. Game Parameters & API Configuration
|
| 28 |
# -----------------------------------------------------------------------------
|
|
@@ -55,7 +54,6 @@ except Exception as e:
|
|
| 55 |
else:
|
| 56 |
st.session_state.initialization_error = None
|
| 57 |
|
| 58 |
-
|
| 59 |
# -----------------------------------------------------------------------------
|
| 60 |
# 3. Core Game Logic Functions
|
| 61 |
# -----------------------------------------------------------------------------
|
|
@@ -121,7 +119,7 @@ def get_llm_order_decision(prompt: str, echelon_name: str) -> (int, str):
|
|
| 121 |
st.warning(f"LLM for {echelon_name} did not return a valid number. Defaulting to 4. Raw Response: '{raw_text}'")
|
| 122 |
return 4, raw_text # Default to 4 if no number found
|
| 123 |
except Exception as e:
|
| 124 |
-
st.error(f"API call failed for {
|
| 125 |
return 4, f"API_ERROR: {e}"
|
| 126 |
|
| 127 |
# =============== MODIFIED FUNCTION (Prompt uses simplified state) ===============
|
|
@@ -557,16 +555,8 @@ else:
|
|
| 557 |
* `Arriving Next Week`: The quantity scheduled to arrive at the start of the **next week**. Use this for your planning.
|
| 558 |
* `Your Total Cumulative Cost`: Sum of all weekly costs up to the **end of last week**.
|
| 559 |
* `Cost Last Week`: The specific cost incurred just **last week**.
|
| 560 |
-
|
| 561 |
-
**C) Your Decision (Step 4 - Two Parts):**
|
| 562 |
-
Now, looking at the dashboard (showing the start-of-week state) and considering the incoming order and future arrivals, you decide how much to order:
|
| 563 |
-
* **(Step 4a - Initial Order):** Submit your first estimate.
|
| 564 |
-
* **(Step 4b - Final Order):** See the AI's suggestion, then submit your final decision. This order will arrive in 3 weeks.
|
| 565 |
-
|
| 566 |
-
Submitting your final order ends the week. The system then calculates your `Weekly Cost` based on your inventory/backlog *after* Step 3 shipping, logs everything, and advances to the next week.
|
| 567 |
""")
|
| 568 |
|
| 569 |
-
|
| 570 |
st.markdown("---")
|
| 571 |
st.header("⚙️ Game Configuration")
|
| 572 |
c1, c2 = st.columns(2)
|
|
@@ -582,7 +572,7 @@ else:
|
|
| 582 |
# --- Main Game Interface ---
|
| 583 |
elif 'game_state' in st.session_state and st.session_state.game_state.get('game_running'):
|
| 584 |
state = st.session_state.game_state
|
| 585 |
-
week, human_role, echelons, info_sharing = state['week'], state['
|
| 586 |
echelon_order = ["Retailer", "Wholesaler", "Distributor", "Factory"] # Define here for UI
|
| 587 |
|
| 588 |
|
|
@@ -595,17 +585,20 @@ else:
|
|
| 595 |
for i, name in enumerate(echelon_order): # Use the defined echelon_order
|
| 596 |
with cols[i]:
|
| 597 |
e, icon = echelons[name], "👤" if name == human_role else "🤖"
|
| 598 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
# Display the END OF LAST WEEK state (which is OPENING state for this week)
|
| 600 |
st.metric("Inventory (Opening)", e['inventory'])
|
| 601 |
st.metric("Backlog (Opening)", e['backlog'])
|
| 602 |
|
| 603 |
-
#
|
| 604 |
-
if name == human_role:
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
st.metric("Cost Last Week", f"${last_week_cost:,.2f}")
|
| 609 |
|
| 610 |
# Display info about THIS week's events / NEXT week's arrivals
|
| 611 |
st.write(f"Incoming Order (This Week): **{e['incoming_order']}**") # Order arriving in Step 2
|
|
@@ -620,7 +613,7 @@ else:
|
|
| 620 |
else:
|
| 621 |
st.info("In Local Information mode, you can only see your own status dashboard.")
|
| 622 |
e = echelons[human_role]
|
| 623 |
-
st.markdown(f"### 👤 {human_role} (Your Dashboard - Start of Week State)")
|
| 624 |
col1, col2, col3, col4 = st.columns(4)
|
| 625 |
# Display OPENING state
|
| 626 |
col1.metric("Inventory (Opening)", e['inventory'])
|
|
@@ -629,9 +622,10 @@ else:
|
|
| 629 |
col3.write(f"**Incoming Order (This Week):**\n# {e['incoming_order']}")
|
| 630 |
col4.write(f"**Shipment Arriving (Next Week):**\n# {list(e['incoming_shipments'])[0] if e['incoming_shipments'] else 0}")
|
| 631 |
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
|
|
|
| 635 |
|
| 636 |
|
| 637 |
st.markdown("---")
|
|
|
|
| 1 |
# app.py
|
| 2 |
+
# @title Beer Game Final Version (v4.18 - UI Adjustments)
|
| 3 |
|
| 4 |
# -----------------------------------------------------------------------------
|
| 5 |
# 1. Import Libraries
|
|
|
|
| 22 |
# -----------------------------------------------------------------------------
|
| 23 |
st.set_page_config(page_title="Beer Game: Human-AI Collaboration", layout="wide")
|
| 24 |
|
|
|
|
| 25 |
# -----------------------------------------------------------------------------
|
| 26 |
# 2. Game Parameters & API Configuration
|
| 27 |
# -----------------------------------------------------------------------------
|
|
|
|
| 54 |
else:
|
| 55 |
st.session_state.initialization_error = None
|
| 56 |
|
|
|
|
| 57 |
# -----------------------------------------------------------------------------
|
| 58 |
# 3. Core Game Logic Functions
|
| 59 |
# -----------------------------------------------------------------------------
|
|
|
|
| 119 |
st.warning(f"LLM for {echelon_name} did not return a valid number. Defaulting to 4. Raw Response: '{raw_text}'")
|
| 120 |
return 4, raw_text # Default to 4 if no number found
|
| 121 |
except Exception as e:
|
| 122 |
+
st.error(f"API call failed for {echelons[human_role]}: {e}. Defaulting to 4.") # Fixed typo: echelon_name -> echelons[human_role]
|
| 123 |
return 4, f"API_ERROR: {e}"
|
| 124 |
|
| 125 |
# =============== MODIFIED FUNCTION (Prompt uses simplified state) ===============
|
|
|
|
| 555 |
* `Arriving Next Week`: The quantity scheduled to arrive at the start of the **next week**. Use this for your planning.
|
| 556 |
* `Your Total Cumulative Cost`: Sum of all weekly costs up to the **end of last week**.
|
| 557 |
* `Cost Last Week`: The specific cost incurred just **last week**.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
""")
|
| 559 |
|
|
|
|
| 560 |
st.markdown("---")
|
| 561 |
st.header("⚙️ Game Configuration")
|
| 562 |
c1, c2 = st.columns(2)
|
|
|
|
| 572 |
# --- Main Game Interface ---
|
| 573 |
elif 'game_state' in st.session_state and st.session_state.game_state.get('game_running'):
|
| 574 |
state = st.session_state.game_state
|
| 575 |
+
week, human_role, echelons, info_sharing = state['week'], state['echelons'], state['human_role'], state['info_sharing']
|
| 576 |
echelon_order = ["Retailer", "Wholesaler", "Distributor", "Factory"] # Define here for UI
|
| 577 |
|
| 578 |
|
|
|
|
| 585 |
for i, name in enumerate(echelon_order): # Use the defined echelon_order
|
| 586 |
with cols[i]:
|
| 587 |
e, icon = echelons[name], "👤" if name == human_role else "🤖"
|
| 588 |
+
if name == human_role:
|
| 589 |
+
# Highlight Distributor for full info mode
|
| 590 |
+
st.markdown(f"##### **<span style='color:#FF4B4B;'>{icon} {name} (You)</span>**", unsafe_allow_html=True) # Highlight
|
| 591 |
+
else:
|
| 592 |
+
st.markdown(f"##### {icon} {name}")
|
| 593 |
# Display the END OF LAST WEEK state (which is OPENING state for this week)
|
| 594 |
st.metric("Inventory (Opening)", e['inventory'])
|
| 595 |
st.metric("Backlog (Opening)", e['backlog'])
|
| 596 |
|
| 597 |
+
# 移除成本显示
|
| 598 |
+
# if name == human_role:
|
| 599 |
+
# st.metric("Total Cost (Cumulative)", f"${e['total_cost']:,.2f}")
|
| 600 |
+
# last_week_cost = state['logs'][-1][f"{human_role}.weekly_cost"] if week > 1 and state['logs'] else 0
|
| 601 |
+
# st.metric("Cost Last Week", f"${last_week_cost:,.2f}")
|
|
|
|
| 602 |
|
| 603 |
# Display info about THIS week's events / NEXT week's arrivals
|
| 604 |
st.write(f"Incoming Order (This Week): **{e['incoming_order']}**") # Order arriving in Step 2
|
|
|
|
| 613 |
else:
|
| 614 |
st.info("In Local Information mode, you can only see your own status dashboard.")
|
| 615 |
e = echelons[human_role]
|
| 616 |
+
st.markdown(f"### 👤 **<span style='color:#FF4B4B;'>{human_role} (Your Dashboard - Start of Week State)</span>**", unsafe_allow_html=True) # Highlight self
|
| 617 |
col1, col2, col3, col4 = st.columns(4)
|
| 618 |
# Display OPENING state
|
| 619 |
col1.metric("Inventory (Opening)", e['inventory'])
|
|
|
|
| 622 |
col3.write(f"**Incoming Order (This Week):**\n# {e['incoming_order']}")
|
| 623 |
col4.write(f"**Shipment Arriving (Next Week):**\n# {list(e['incoming_shipments'])[0] if e['incoming_shipments'] else 0}")
|
| 624 |
|
| 625 |
+
# 移除成本显示
|
| 626 |
+
# st.metric("Your Total Cumulative Cost", f"${e['total_cost']:,.2f}")
|
| 627 |
+
# last_week_cost = state['logs'][-1][f"{human_role}.weekly_cost"] if week > 1 and state['logs'] else 0
|
| 628 |
+
# st.metric("Cost Last Week", f"${last_week_cost:,.2f}")
|
| 629 |
|
| 630 |
|
| 631 |
st.markdown("---")
|