oscarwang2 commited on
Commit
245fa34
1 Parent(s): ca2baa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -42,7 +42,7 @@ def generate_and_save_data():
42
  messages=[
43
  {
44
  "role": "user",
45
- "content": "give me a single prompt to prompt an ai model, simulating what users could want from you. ensure that it is diverse and high quality. for each, choose a random writing style (though it has to be a common one), random length and random clarity of the prompt. ensure that I is a single prompt, and just the prompt itself, nothing else. eg, don't close the prompt in quotation marks or say Here is a single prompt that meets your requirements or anything similar to that"
46
  }
47
  ],
48
  temperature=1,
@@ -102,12 +102,10 @@ def generate_and_save_data():
102
  # Create the new file with headers
103
  with open(current_file, 'w') as f:
104
  data.to_csv(f, header=True, index=False)
105
- f.flush()
106
  else:
107
  # Append data to the current file
108
  with open(current_file, 'a') as f:
109
  data.to_csv(f, header=False, index=False)
110
- f.flush()
111
 
112
  # Wait for the next update interval
113
  time.sleep(UPDATE_INTERVAL)
@@ -128,6 +126,12 @@ def update_file_list():
128
  def update_token_count():
129
  return combined_tokens
130
 
 
 
 
 
 
 
131
  # Start the data generation in a separate thread
132
  thread = threading.Thread(target=generate_and_save_data)
133
  thread.daemon = True
@@ -138,7 +142,8 @@ with gr.Blocks() as app:
138
  gr.Markdown("## AI Prompt and Response Generator")
139
  gr.Markdown("This app continuously generates AI prompts and responses, and writes them to CSV files.")
140
 
141
- file_selector = gr.Dropdown(label="Select a data file to download", choices=get_available_files())
 
142
  download_button = gr.File(label="Download Selected File")
143
 
144
  def download_file(selected_file):
@@ -146,6 +151,7 @@ with gr.Blocks() as app:
146
 
147
  refresh_button = gr.Button("Refresh File List")
148
  refresh_button.click(update_file_list, outputs=file_selector)
 
149
  file_selector.change(download_file, inputs=file_selector, outputs=download_button)
150
 
151
  token_display = gr.Textbox(label="Combined Tokens", value=str(update_token_count()), interactive=False)
 
42
  messages=[
43
  {
44
  "role": "user",
45
+ "content": "give me a single prompt to prompt an ai model, simulating what users could want from you. ensure that it is diverse and high quality. for each, choose a random writing style (though it has to be a common one), random length and random clarity of the prompt. ensure that it is a single prompt, and just the prompt itself, nothing else. eg, don't close the prompt in quotation marks or say Here is a single prompt that meets your requirements or anything similar to that"
46
  }
47
  ],
48
  temperature=1,
 
102
  # Create the new file with headers
103
  with open(current_file, 'w') as f:
104
  data.to_csv(f, header=True, index=False)
 
105
  else:
106
  # Append data to the current file
107
  with open(current_file, 'a') as f:
108
  data.to_csv(f, header=False, index=False)
 
109
 
110
  # Wait for the next update interval
111
  time.sleep(UPDATE_INTERVAL)
 
126
  def update_token_count():
127
  return combined_tokens
128
 
129
+ # Display file content
130
+ def display_file_content(selected_file):
131
+ if selected_file:
132
+ return pd.read_csv(selected_file)
133
+ return pd.DataFrame()
134
+
135
  # Start the data generation in a separate thread
136
  thread = threading.Thread(target=generate_and_save_data)
137
  thread.daemon = True
 
142
  gr.Markdown("## AI Prompt and Response Generator")
143
  gr.Markdown("This app continuously generates AI prompts and responses, and writes them to CSV files.")
144
 
145
+ file_selector = gr.Dropdown(label="Select a data file to view and download", choices=get_available_files())
146
+ file_viewer = gr.DataFrame(label="CSV File Content")
147
  download_button = gr.File(label="Download Selected File")
148
 
149
  def download_file(selected_file):
 
151
 
152
  refresh_button = gr.Button("Refresh File List")
153
  refresh_button.click(update_file_list, outputs=file_selector)
154
+ file_selector.change(display_file_content, inputs=file_selector, outputs=file_viewer)
155
  file_selector.change(download_file, inputs=file_selector, outputs=download_button)
156
 
157
  token_display = gr.Textbox(label="Combined Tokens", value=str(update_token_count()), interactive=False)