Remek commited on
Commit
6bbb741
1 Parent(s): fc799c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import json
 
3
 
4
  class JSONLViewer:
5
  def __init__(self, file_path):
@@ -9,8 +10,11 @@ class JSONLViewer:
9
  self.load_data()
10
 
11
  def load_data(self):
12
- with open(self.file_path, 'r', encoding='utf-8') as file:
13
- self.data = [json.loads(line) for line in file]
 
 
 
14
 
15
  def save_data(self):
16
  with open(self.file_path, 'w', encoding='utf-8') as file:
@@ -70,7 +74,7 @@ def on_rejected():
70
  record = viewer.get_current_record()
71
  return update_ui(record)
72
 
73
- with gr.Blocks() as demo:
74
  instruction = gr.Textbox(label="INSTRUCTION", lines=8, max_lines=8)
75
  chosen = gr.Textbox(label="CHOSEN", lines=8, max_lines=8)
76
  rejected = gr.Textbox(label="REJECTED", lines=8, max_lines=8)
@@ -81,8 +85,8 @@ with gr.Blocks() as demo:
81
  with gr.Row():
82
  prev_btn = gr.Button("PREV")
83
  next_btn = gr.Button("NEXT")
84
- ok_btn = gr.Button("OK", variant="primary") # Zielony przycisk
85
- rejected_btn = gr.Button("REJECTED", variant="stop") # Czerwony przycisk
86
 
87
  prev_btn.click(on_prev, outputs=[instruction, chosen, rejected, chosen_score, rejected_score, status])
88
  next_btn.click(on_next, outputs=[instruction, chosen, rejected, chosen_score, rejected_score, status])
@@ -100,4 +104,5 @@ with gr.Blocks() as demo:
100
  rejected_score.value = init_rejected_score
101
  status.value = init_status
102
 
103
- demo.launch()
 
 
1
  import gradio as gr
2
  import json
3
+ import os
4
 
5
  class JSONLViewer:
6
  def __init__(self, file_path):
 
10
  self.load_data()
11
 
12
  def load_data(self):
13
+ if os.path.exists(self.file_path):
14
+ with open(self.file_path, 'r', encoding='utf-8') as file:
15
+ self.data = [json.loads(line) for line in file]
16
+ else:
17
+ self.data = []
18
 
19
  def save_data(self):
20
  with open(self.file_path, 'w', encoding='utf-8') as file:
 
74
  record = viewer.get_current_record()
75
  return update_ui(record)
76
 
77
+ with gr.Blocks(css="button.ok-button { background-color: #4CAF50 !important; }") as demo:
78
  instruction = gr.Textbox(label="INSTRUCTION", lines=8, max_lines=8)
79
  chosen = gr.Textbox(label="CHOSEN", lines=8, max_lines=8)
80
  rejected = gr.Textbox(label="REJECTED", lines=8, max_lines=8)
 
85
  with gr.Row():
86
  prev_btn = gr.Button("PREV")
87
  next_btn = gr.Button("NEXT")
88
+ ok_btn = gr.Button("OK", elem_classes="ok-button")
89
+ rejected_btn = gr.Button("REJECTED", variant="stop")
90
 
91
  prev_btn.click(on_prev, outputs=[instruction, chosen, rejected, chosen_score, rejected_score, status])
92
  next_btn.click(on_next, outputs=[instruction, chosen, rejected, chosen_score, rejected_score, status])
 
104
  rejected_score.value = init_rejected_score
105
  status.value = init_status
106
 
107
+ if __name__ == "__main__":
108
+ demo.launch()