Allen Park commited on
Commit
34e4cb8
·
1 Parent(s): 82e1308

add non interactive textbox below input to display uploaded file

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -132,11 +132,14 @@ def model_call(question, document, answer, client_base_url):
132
  return combined_reasoning, score
133
 
134
  def upload_file(filepath):
135
- name = Path(filepath).name
136
- return [gr.UploadButton(visible=False), gr.ClearButton(visible=True)]
 
 
 
137
  # return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
138
  def reset_buttons():
139
- return [gr.UploadButton(visible=True), gr.ClearButton(visible=False)]
140
 
141
  # def download_file():
142
  # return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
@@ -163,6 +166,7 @@ with gr.Blocks(css=css) as demo:
163
  u = gr.UploadButton("Upload", file_count="single", scale=1)
164
  c = gr.ClearButton([u], visible=False, scale=1)
165
  # d = gr.DownloadButton("Download the file", visible=False, scale=1)
 
166
  with gr.Row():
167
  document = gr.Textbox(label="Document")
168
  with gr.Row():
@@ -175,8 +179,8 @@ with gr.Blocks(css=css) as demo:
175
  score = gr.Textbox(label="Score (FAIL if Hallucinated, PASS if not)")
176
 
177
  model_dropdown.change(fn=update_client_base_url, inputs=[model_dropdown], outputs=[base_url_state])
178
- u.upload(upload_file, u, [u, c])
179
- c.click(reset_buttons, None, [u, c])
180
  # d.click(download_file, None, [u, d])
181
 
182
  submit_button.click(fn=model_call, inputs=[question, document, answer, base_url_state], outputs=[reasoning, score])
 
132
  return combined_reasoning, score
133
 
134
  def upload_file(filepath):
135
+ if filepath is not None:
136
+ name = Path(filepath).name
137
+ return [gr.UploadButton(visible=False), gr.ClearButton(visible=True), gr.Textbox(value=name, interactive=False)]
138
+ else:
139
+ return [gr.UploadButton(visible=True), gr.ClearButton(visible=False), gr.Textbox(value="", interactive=False)]
140
  # return [gr.UploadButton(visible=False), gr.DownloadButton(label=f"Download {name}", value=filepath, visible=True)]
141
  def reset_buttons():
142
+ return [gr.UploadButton(visible=True), gr.ClearButton(visible=False), gr.Textbox(value="", interactive=False)]
143
 
144
  # def download_file():
145
  # return [gr.UploadButton(visible=True), gr.DownloadButton(visible=False)]
 
166
  u = gr.UploadButton("Upload", file_count="single", scale=1)
167
  c = gr.ClearButton([u], visible=False, scale=1)
168
  # d = gr.DownloadButton("Download the file", visible=False, scale=1)
169
+ file_name = gr.Textbox(label="Uploaded File", interactive=False)
170
  with gr.Row():
171
  document = gr.Textbox(label="Document")
172
  with gr.Row():
 
179
  score = gr.Textbox(label="Score (FAIL if Hallucinated, PASS if not)")
180
 
181
  model_dropdown.change(fn=update_client_base_url, inputs=[model_dropdown], outputs=[base_url_state])
182
+ u.upload(upload_file, u, [u, c, file_name])
183
+ c.click(reset_buttons, None, [u, c, file_name])
184
  # d.click(download_file, None, [u, d])
185
 
186
  submit_button.click(fn=model_call, inputs=[question, document, answer, base_url_state], outputs=[reasoning, score])