wuhp commited on
Commit
ed79407
·
verified ·
1 Parent(s): 42d9d3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -37,12 +37,15 @@ class ReportSender:
37
  self.stop_event.clear() # Clear any previous stop signal
38
  self.is_running = True
39
 
40
- master_urls = [u.strip() for u in master_url_batch.split('\n') if u.strip().startswith('http')]
 
 
 
41
  num_urls = len(master_urls)
42
 
43
  if not master_urls:
44
  self.is_running = False
45
- yield "❌ Error: No valid URLs found in the Report URL Batch input. Ensure each URL starts with 'http'.", False, "Stopped"
46
  return
47
 
48
  # Use the full User-Agent found in your working request logs (Chrome 143)
@@ -102,7 +105,9 @@ class ReportSender:
102
  if error_msg:
103
  try:
104
  parsed = response.json()
105
- error_msg = parsed.get('status_message', f"Code: {parsed.get('status_code', '???')}")
 
 
106
  except:
107
  error_msg = response.text[:50] + "..."
108
  else:
@@ -152,7 +157,8 @@ class ReportSender:
152
 
153
  sender = ReportSender()
154
 
155
- with gr.Blocks(theme=gr.themes.Soft()) as app:
 
156
  gr.Markdown("# 🤖 TikTok Master Report Sender (Continuous)")
157
 
158
  # State variable to track if the loop is running (used for button interactivity)
@@ -182,14 +188,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
182
  )
183
 
184
  gr.Markdown("### 3. Loop Control")
185
- with gr.Row(equal_height=False): # Set equal_height=False to control individual scaling
 
186
  batch_count_input = gr.Number(
187
  label="Batch Count (Total Cycles)",
188
- info="Set to -1 for continuous run. E.g., 5 means the batch runs 5 times.",
189
  value=5,
190
  scale=1
191
  )
192
- # Status box is now separate
193
  status_box = gr.Textbox(label="Status", value="Stopped", interactive=False, scale=1)
194
 
195
  with gr.Row():
@@ -210,7 +217,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
210
  # --- Button Logic ---
211
 
212
  # Start button click calls the loop directly (as a generator)
213
- # The output from the generator is the tuple: (logs, is_running_state, status_box)
214
  send_btn.click(
215
  fn=sender.execute_reports_loop,
216
  inputs=[master_url_batch_input, cookie_input, batch_count_input, current_status],
@@ -241,5 +247,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
241
 
242
 
243
  if __name__ == "__main__":
244
- # Removed theme from Blocks and placed it in launch() as per Gradio warning
245
  app.launch(theme=gr.themes.Soft())
 
37
  self.stop_event.clear() # Clear any previous stop signal
38
  self.is_running = True
39
 
40
+ # --- FIX: Only check for non-empty lines, assume valid URL format (http/https) ---
41
+ master_urls = [u.strip() for u in master_url_batch.split('\n') if u.strip()]
42
+ # ---------------------------------------------------------------------------------
43
+
44
  num_urls = len(master_urls)
45
 
46
  if not master_urls:
47
  self.is_running = False
48
+ yield "❌ Error: No valid URLs found in the Report URL Batch input. Ensure each URL starts with 'http' or 'https'.", False, "Stopped"
49
  return
50
 
51
  # Use the full User-Agent found in your working request logs (Chrome 143)
 
105
  if error_msg:
106
  try:
107
  parsed = response.json()
108
+ status_code = parsed.get('status_code', '???')
109
+ status_message = parsed.get('status_message', 'No Message')
110
+ error_msg = f"Code: {status_code} | Msg: {status_message}"
111
  except:
112
  error_msg = response.text[:50] + "..."
113
  else:
 
157
 
158
  sender = ReportSender()
159
 
160
+ # The theme parameter is moved to launch() to resolve the Gradio warning
161
+ with gr.Blocks() as app:
162
  gr.Markdown("# 🤖 TikTok Master Report Sender (Continuous)")
163
 
164
  # State variable to track if the loop is running (used for button interactivity)
 
188
  )
189
 
190
  gr.Markdown("### 3. Loop Control")
191
+ # Fixed UI layout for this row
192
+ with gr.Row(equal_height=False):
193
  batch_count_input = gr.Number(
194
  label="Batch Count (Total Cycles)",
195
+ info="Set to -1 for continuous run.",
196
  value=5,
197
  scale=1
198
  )
199
+ # Status box fix: set scale to 1 for better proportion
200
  status_box = gr.Textbox(label="Status", value="Stopped", interactive=False, scale=1)
201
 
202
  with gr.Row():
 
217
  # --- Button Logic ---
218
 
219
  # Start button click calls the loop directly (as a generator)
 
220
  send_btn.click(
221
  fn=sender.execute_reports_loop,
222
  inputs=[master_url_batch_input, cookie_input, batch_count_input, current_status],
 
247
 
248
 
249
  if __name__ == "__main__":
 
250
  app.launch(theme=gr.themes.Soft())