bebechien commited on
Commit
69c5213
·
verified ·
1 Parent(s): 7a33ddf

Fix Tab 3

Browse files
Files changed (2) hide show
  1. src/session_manager.py +24 -21
  2. src/ui.py +14 -11
src/session_manager.py CHANGED
@@ -219,22 +219,18 @@ class HackerNewsFineTuner:
219
  """
220
  if self.model is None:
221
  raise gr.Error("Model not loaded.")
222
-
223
- # Validation
224
- if not pos_ids:
225
- raise gr.Error("Please select at least one 'Favorite' story.")
226
- if not neg_ids:
227
- raise gr.Error("Please select at least one 'Dislike' story.")
228
-
229
- # Generate Dataset
230
- hn_dataset = self._create_hn_dataset(pos_ids, neg_ids)
231
-
232
- # Merge with imported dataset if it exists
233
  if self.imported_dataset:
234
- # If we have both, combine them
235
- self.last_hn_dataset = hn_dataset + self.imported_dataset
236
  else:
237
- self.last_hn_dataset = hn_dataset
 
 
 
 
 
 
 
238
 
239
  if not self.last_hn_dataset:
240
  raise gr.Error("Dataset generation failed (Empty dataset).")
@@ -264,22 +260,29 @@ class HackerNewsFineTuner:
264
 
265
  ## Vibe Check Logic ##
266
  def get_vibe_check(self, news_text: str) -> Tuple[str, str, gr.update]:
267
- info_text = f"**Session:** {self.session_id[:6]}<br>**Model:** `{self.config.MODEL_NAME}`{' - Fine-tuned' if self.last_hn_dataset else ''}"
 
 
 
 
 
 
268
 
269
  if not self.vibe_checker:
270
- return "N/A", "Model Loading...", gr.update(value=self._generate_vibe_html("gray")), info_text
271
  if not news_text or len(news_text.split()) < 3:
272
- return "N/A", "Text too short", gr.update(value=self._generate_vibe_html("white")), info_text
273
 
274
  try:
275
  vibe_result = self.vibe_checker.check(news_text)
276
  status = vibe_result.status_html.split('>')[1].split('<')[0]
277
- return f"{vibe_result.raw_score:.4f}", status, gr.update(value=self._generate_vibe_html(vibe_result.color_hsl)), info_text
278
  except Exception as e:
279
- return "N/A", f"Error: {e}", gr.update(value=self._generate_vibe_html("gray")), info_text
280
 
281
- def _generate_vibe_html(self, color: str) -> str:
282
- return f'<div style="background-color: {color}; height: 100px; border-radius: 12px; border: 2px solid #ccc;"></div>'
 
283
 
284
  ## Mood Reader Logic ##
285
  def fetch_and_display_mood_feed(self) -> str:
 
219
  """
220
  if self.model is None:
221
  raise gr.Error("Model not loaded.")
222
+
 
 
 
 
 
 
 
 
 
 
223
  if self.imported_dataset:
224
+ self.last_hn_dataset = self.imported_dataset
 
225
  else:
226
+ # Validation
227
+ if not pos_ids:
228
+ raise gr.Error("Please select at least one 'Favorite' story.")
229
+ if not neg_ids:
230
+ raise gr.Error("Please select at least one 'Dislike' story.")
231
+
232
+ # Generate Dataset
233
+ self.last_hn_dataset = self._create_hn_dataset(pos_ids, neg_ids)
234
 
235
  if not self.last_hn_dataset:
236
  raise gr.Error("Dataset generation failed (Empty dataset).")
 
260
 
261
  ## Vibe Check Logic ##
262
  def get_vibe_check(self, news_text: str) -> Tuple[str, str, gr.update]:
263
+ model_name = "<unsaved>"
264
+ if self.last_hn_dataset:
265
+ model_name = f"./{self.output_dir}"
266
+
267
+ info_text = (f"**Session:** {self.session_id[:6]}<br>"
268
+ f"**Base Model:** `{self.config.MODEL_NAME}`<br>"
269
+ f"**Tuned Model:** `{model_name}`")
270
 
271
  if not self.vibe_checker:
272
+ return "N/A", "Model Loading...", gr.update(value=self._generate_vibe_css("gray")), info_text
273
  if not news_text or len(news_text.split()) < 3:
274
+ return "N/A", "Text too short", gr.update(value=self._generate_vibe_css("gray")), info_text
275
 
276
  try:
277
  vibe_result = self.vibe_checker.check(news_text)
278
  status = vibe_result.status_html.split('>')[1].split('<')[0]
279
+ return f"{vibe_result.raw_score:.4f}", status, gr.update(value=self._generate_vibe_css(vibe_result.color_hsl)), info_text
280
  except Exception as e:
281
+ return "N/A", f"Error: {e}", gr.update(value=self._generate_vibe_css("gray")), info_text
282
 
283
+ def _generate_vibe_css(self, color: str) -> str:
284
+ """Generates a style block to update the Mood Lamp textbox background."""
285
+ return f"<style>#mood_lamp input {{ background-color: {color} !important; transition: background-color 0.5s ease; }}</style>"
286
 
287
  ## Mood Reader Logic ##
288
  def fetch_and_display_mood_feed(self) -> str:
src/ui.py CHANGED
@@ -361,10 +361,10 @@ def build_interface() -> gr.Blocks:
361
  with gr.Tab("🧪 Vibe Check Playground"):
362
  with gr.Column():
363
  gr.Markdown(f"## News Similarity Check")
364
- gr.Markdown(f"Enter text to see its similarity to **`{AppConfig.QUERY_ANCHOR}`**.\n**Vibe Key:** Green = High, Red = Low")
365
- news_input = gr.Textbox(label="Enter News Title or Summary", lines=3)
366
- vibe_check_btn = gr.Button("Check Similarity", variant="primary")
367
-
368
  gr.Examples(
369
  examples=[
370
  "Global Markets Rally as Inflation Data Shows Unexpected Drop for Third Consecutive Month",
@@ -376,19 +376,22 @@ def build_interface() -> gr.Blocks:
376
  inputs=news_input,
377
  label="Try these examples"
378
  )
379
-
 
 
 
380
  session_info_display = gr.Markdown()
381
 
382
- with gr.Row():
383
- vibe_color_block = gr.HTML(value='<div style="background-color: gray; height: 100px;"></div>', label="Mood Lamp")
384
- with gr.Column():
385
- vibe_score = gr.Textbox(label="Score", value="N/A", interactive=False)
386
- vibe_status = gr.Textbox(label="Status", value="...", interactive=False)
387
 
388
  vibe_check_btn.click(
389
  fn=vibe_check_wrapper,
390
  inputs=[session_state, news_input],
391
- outputs=[vibe_score, vibe_status, vibe_color_block, session_info_display]
392
  )
393
 
394
  return demo
 
361
  with gr.Tab("🧪 Vibe Check Playground"):
362
  with gr.Column():
363
  gr.Markdown(f"## News Similarity Check")
364
+ gr.Markdown(f"Enter text to see its similarity to **`{AppConfig.QUERY_ANCHOR}`**.<br>**Vibe Key:** <span style='color:green'>Green = High</span>, <span style='color:yellow'>Yellow = Neutral</span>, <span style='color:red'>Red = Low</span>")
365
+
366
+ news_input = gr.Textbox(label="Enter News Title or Summary", lines=3, render=False)
367
+
368
  gr.Examples(
369
  examples=[
370
  "Global Markets Rally as Inflation Data Shows Unexpected Drop for Third Consecutive Month",
 
376
  inputs=news_input,
377
  label="Try these examples"
378
  )
379
+
380
+ news_input.render()
381
+ vibe_check_btn = gr.Button("Check Similarity", variant="primary")
382
+
383
  session_info_display = gr.Markdown()
384
 
385
+ with gr.Column():
386
+ vibe_score = gr.Textbox(label="Score", value="N/A", interactive=False)
387
+ vibe_lamp = gr.Textbox(label="Mood Lamp", max_lines=1, elem_id="mood_lamp", interactive=False)
388
+ vibe_status = gr.Textbox(label="Status", value="...", interactive=False)
389
+ style_thml = gr.HTML(value="<style>#mood_lamp input {background-color: gray;}</style>")
390
 
391
  vibe_check_btn.click(
392
  fn=vibe_check_wrapper,
393
  inputs=[session_state, news_input],
394
+ outputs=[vibe_score, vibe_status, style_thml, session_info_display]
395
  )
396
 
397
  return demo