rui3000 commited on
Commit
c14b073
·
verified ·
1 Parent(s): ccd03a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -53,7 +53,6 @@ def generate_response(messages, max_length=512, temperature=0.7, top_p=0.9):
53
  print(f"Error during generation: {e}")
54
  return f"An error occurred: {str(e)}", num_generated_tokens
55
 
56
- # --- Input Processing Function (Takes single system prompt) ---
57
  @spaces.GPU # Keep ZeroGPU decorator
58
  def process_input(
59
  analysis_mode, # Mode selector
@@ -66,19 +65,18 @@ def process_input(
66
  """Process inputs based on selected analysis mode using the provided system prompt."""
67
  print(f"GPU requested via decorator, starting processing in mode: {analysis_mode}")
68
 
69
- # Construct user content based on mode
70
- if analysis_mode == "Frequency Only":
71
- user_content = f"Player Move Frequency Stats (Long-Term):\n{player_stats}"
72
- elif analysis_mode == "Markov Prediction Only":
73
- user_content = "Analyze based on the system prompt instructions."
74
- else:
75
- return "Invalid analysis mode selected.", "", "0 seconds", 0
76
-
77
- # Create the messages list using the system_prompt from the UI
78
  messages = []
79
  if system_prompt and system_prompt.strip():
80
  messages.append({"role": "system", "content": system_prompt})
81
- messages.append({"role": "user", "content": user_content})
 
 
 
 
 
 
 
82
 
83
  # --- Time Measurement Start ---
84
  start_time = time.time()
@@ -95,8 +93,11 @@ def process_input(
95
  end_time = time.time()
96
  duration = round(end_time - start_time, 2)
97
 
98
- # For display purposes
99
- display_prompt = f"Selected Mode: {analysis_mode}\nSystem Prompt:\n{system_prompt}\n\n------\n\nUser Content:\n{user_content}"
 
 
 
100
 
101
  print(f"Processing finished in {duration} seconds.")
102
  # Return all results including time and tokens
 
53
  print(f"Error during generation: {e}")
54
  return f"An error occurred: {str(e)}", num_generated_tokens
55
 
 
56
  @spaces.GPU # Keep ZeroGPU decorator
57
  def process_input(
58
  analysis_mode, # Mode selector
 
65
  """Process inputs based on selected analysis mode using the provided system prompt."""
66
  print(f"GPU requested via decorator, starting processing in mode: {analysis_mode}")
67
 
68
+ # Create the messages list using the system_prompt from the UI directly
 
 
 
 
 
 
 
 
69
  messages = []
70
  if system_prompt and system_prompt.strip():
71
  messages.append({"role": "system", "content": system_prompt})
72
+
73
+ # Add an empty user message or specific content based on analysis mode
74
+ if analysis_mode == "Frequency Only":
75
+ user_content = f"Player Move Frequency Stats (Long-Term):\n{player_stats}"
76
+ messages.append({"role": "user", "content": user_content})
77
+ else: # For Markov Prediction or any other mode
78
+ # Just add an empty user message to trigger the model response
79
+ messages.append({"role": "user", "content": ""})
80
 
81
  # --- Time Measurement Start ---
82
  start_time = time.time()
 
93
  end_time = time.time()
94
  duration = round(end_time - start_time, 2)
95
 
96
+ # For display purposes - show what was actually sent to the model
97
+ if analysis_mode == "Frequency Only":
98
+ display_prompt = f"Selected Mode: {analysis_mode}\nSystem Prompt:\n{system_prompt}\n\n------\n\nUser Content:\n{user_content}"
99
+ else:
100
+ display_prompt = f"Selected Mode: {analysis_mode}\nSystem Prompt:\n{system_prompt}\n\n------\n\nUser Content:\n[Empty]"
101
 
102
  print(f"Processing finished in {duration} seconds.")
103
  # Return all results including time and tokens