ar12c commited on
Commit
b4d350f
·
verified ·
1 Parent(s): a1598c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -2,7 +2,7 @@
2
  # OkemoLLM backend — Streaming responses + DuckDuckGo + Increased Web Retention
3
 
4
  import os
5
- import re # <-- Ensure re is imported
6
  import math
7
  import unicodedata
8
  import requests
@@ -47,8 +47,7 @@ TRAIN_INPUT_STATE = {} # Initial value for the Gradio State
47
  def to_ascii(text: Optional[str]) -> str:
48
  return unicodedata.normalize("NFKC", text or "")
49
 
50
- # FIX: Changed flags=torch.UNICODE to flags=re.UNICODE
51
- _TOKEN_RE = re.compile(r"\w+|[^\w\s]", flags=re.UNICODE)
52
 
53
  def tokenize(text: str) -> List[str]:
54
  return _TOKEN_RE.findall(to_ascii(text).lower())
@@ -483,16 +482,16 @@ with gr.Blocks(title="OkemoLLM") as demo:
483
  train_state = gr.State(TRAIN_INPUT_STATE)
484
 
485
  with gr.Row():
486
- msg = gr.Textbox(placeholder='Type your message (Training is now manual).', label="Message", scale=4)
487
  clear = gr.Button("Clear", scale=1)
488
 
489
  gr.Markdown("---")
490
  gr.Markdown("## ⚙️ Manual Feedback Training")
491
- gr.Markdown("Use this section to train the model with a **correct answer** after a poor response.")
492
 
493
  with gr.Column():
494
  # Defining the train_status component here
495
- train_status = gr.Markdown("Submit a message, then enter the desired response below and click 'Train'.")
496
 
497
  # This displays the last user input
498
  prompt_display = gr.Textbox(label="Last User Message (Input for Training)", interactive=False)
@@ -504,6 +503,7 @@ with gr.Blocks(title="OkemoLLM") as demo:
504
  train_button = gr.Button("Perform Manual Feedback Training")
505
 
506
  # Connect Chat Handlers (Inference only)
 
507
  msg.submit(
508
  on_submit,
509
  [msg, chat, train_state],
@@ -517,16 +517,14 @@ with gr.Blocks(title="OkemoLLM") as demo:
517
 
518
  clear.click(lambda: ([], f"Cleared. Current Checkpoint Iteration: {start_iteration}."), None, [chat, status], queue=False)
519
 
520
- # Connect the Manual Training Button
521
  train_button.click(
522
  feedback_train,
523
- [chat, manual_target_response],
524
  train_status
525
  )
526
-
527
- # Register the manual training function as an API endpoint for the frontend
528
- demo.api_add_function(feedback_train, "feedback_train")
529
 
530
 
531
  if __name__ == "__main__":
 
532
  demo.queue(api_open=True).launch(ssr_mode=False)
 
2
  # OkemoLLM backend — Streaming responses + DuckDuckGo + Increased Web Retention
3
 
4
  import os
5
+ import re
6
  import math
7
  import unicodedata
8
  import requests
 
47
  def to_ascii(text: Optional[str]) -> str:
48
  return unicodedata.normalize("NFKC", text or "")
49
 
50
+ _TOKEN_RE = re.compile(r"\w+|[^\w\s]", flags=re.UNICODE)
 
51
 
52
  def tokenize(text: str) -> List[str]:
53
  return _TOKEN_RE.findall(to_ascii(text).lower())
 
482
  train_state = gr.State(TRAIN_INPUT_STATE)
483
 
484
  with gr.Row():
485
+ msg = gr.Textbox(placeholder='Type your message.', label="Message", scale=4)
486
  clear = gr.Button("Clear", scale=1)
487
 
488
  gr.Markdown("---")
489
  gr.Markdown("## ⚙️ Manual Feedback Training")
490
+ gr.Markdown("Use this section to train the model with a **correct answer** after a poor response. The Bad Feedback button in the chat calls this function.")
491
 
492
  with gr.Column():
493
  # Defining the train_status component here
494
+ train_status = gr.Markdown("Status will update after clicking 'Train'.")
495
 
496
  # This displays the last user input
497
  prompt_display = gr.Textbox(label="Last User Message (Input for Training)", interactive=False)
 
503
  train_button = gr.Button("Perform Manual Feedback Training")
504
 
505
  # Connect Chat Handlers (Inference only)
506
+ # The output of on_submit is [history, status, train_state]
507
  msg.submit(
508
  on_submit,
509
  [msg, chat, train_state],
 
517
 
518
  clear.click(lambda: ([], f"Cleared. Current Checkpoint Iteration: {start_iteration}."), None, [chat, status], queue=False)
519
 
520
+ # Connect the Manual Training Button (This also implicitly registers the /feedback_train endpoint)
521
  train_button.click(
522
  feedback_train,
523
+ [chat, manual_target_response], # chat component passes the history
524
  train_status
525
  )
 
 
 
526
 
527
 
528
  if __name__ == "__main__":
529
+ # NOTE: demo.api_add_function is removed, relying on Gradio's implicit registration
530
  demo.queue(api_open=True).launch(ssr_mode=False)