Yulu Fu commited on
Commit
f753e4b
1 Parent(s): 33b18b9

Update placeholder for image

Browse files
Files changed (1) hide show
  1. app.py +10 -21
app.py CHANGED
@@ -25,34 +25,23 @@ def predict(data, model_choice):
25
  print("Error during prediction:", e) # Debugging statement
26
  return {"error": str(e)}
27
 
28
- # Define the interface based on the selected model
29
  def update_interface(model_choice):
30
  if model_choice == "Audio Deepfake Detection":
31
- return gr.Audio(type="filepath"), gr.Label()
32
  elif model_choice == "Image Deepfake Detection":
33
- return gr.Image(type="filepath"), gr.Label()
34
- else:
35
- return None, None
36
 
37
  # Create the Gradio interface
38
  with gr.Blocks() as iface:
39
  model_choice = gr.Radio(choices=["Audio Deepfake Detection", "Image Deepfake Detection"], label="Select Model", value="Audio Deepfake Detection")
40
- input_component, output_component = update_interface(model_choice.value)
41
-
42
- def update_inputs(model_choice):
43
- input_component, output_component = update_interface(model_choice)
44
- input_placeholder.update(visible=False)
45
- output_placeholder.update(visible=False)
46
- input_placeholder.update(visible=True, component=input_component)
47
- output_placeholder.update(visible=True, component=output_component)
48
-
49
- input_placeholder = gr.Placeholder(gr.Component, visible=True)
50
- output_placeholder = gr.Placeholder(gr.Component, visible=True)
51
-
52
- model_choice.change(fn=update_inputs, inputs=model_choice, outputs=[input_placeholder, output_placeholder])
53
-
54
  submit_button = gr.Button("Submit")
55
- submit_button.click(fn=predict, inputs=[input_placeholder, model_choice], outputs=output_placeholder)
56
 
57
  iface.launch()
58
-
 
25
  print("Error during prediction:", e) # Debugging statement
26
  return {"error": str(e)}
27
 
28
+ # Function to update the interface based on the selected model
29
  def update_interface(model_choice):
30
  if model_choice == "Audio Deepfake Detection":
31
+ return gr.update(visible=True), gr.update(visible=False)
32
  elif model_choice == "Image Deepfake Detection":
33
+ return gr.update(visible=False), gr.update(visible=True)
 
 
34
 
35
  # Create the Gradio interface
36
  with gr.Blocks() as iface:
37
  model_choice = gr.Radio(choices=["Audio Deepfake Detection", "Image Deepfake Detection"], label="Select Model", value="Audio Deepfake Detection")
38
+ audio_input = gr.Audio(type="filepath", label="Upload Audio File")
39
+ image_input = gr.Image(type="filepath", label="Upload Image File", visible=False)
40
+ output = gr.Label()
41
+
42
+ model_choice.change(fn=update_interface, inputs=model_choice, outputs=[audio_input, image_input])
43
+
 
 
 
 
 
 
 
 
44
  submit_button = gr.Button("Submit")
45
+ submit_button.click(fn=predict, inputs=[gr.State(audio_input), gr.State(image_input), model_choice], outputs=output)
46
 
47
  iface.launch()