AlirezaF138 commited on
Commit
5c0bb25
·
verified ·
1 Parent(s): 0d21fa6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -50,6 +50,15 @@ def on_random_click():
50
  updates.append(texture)
51
  return updates
52
 
 
 
 
 
 
 
 
 
 
53
  # Create Gradio interface
54
  with gr.Blocks() as demo:
55
  with gr.Row():
@@ -65,11 +74,16 @@ with gr.Blocks() as demo:
65
  label=component_names[i]
66
  )
67
  sliders.append(slider)
68
- random_button = gr.Button("Randomize Texture")
69
  with gr.Column():
70
  output_image = gr.Image(
71
  label="Generated Texture"
72
  )
 
 
 
 
 
 
73
 
74
  # Update texture when any slider changes
75
  for slider in sliders:
@@ -86,4 +100,11 @@ with gr.Blocks() as demo:
86
  outputs=[*sliders, output_image]
87
  )
88
 
 
 
 
 
 
 
 
89
  demo.launch()
 
50
  updates.append(texture)
51
  return updates
52
 
53
+ def on_image_upload(image):
54
+ # Process the uploaded image and get PCA coefficients
55
+ coefficients = process_uploaded_image(image)
56
+ texture = generate_texture(*coefficients)
57
+ # Update sliders and image
58
+ updates = [gr.update(value=value) for value in coefficients]
59
+ updates.append(texture)
60
+ return updates
61
+
62
  # Create Gradio interface
63
  with gr.Blocks() as demo:
64
  with gr.Row():
 
74
  label=component_names[i]
75
  )
76
  sliders.append(slider)
 
77
  with gr.Column():
78
  output_image = gr.Image(
79
  label="Generated Texture"
80
  )
81
+ random_button = gr.Button("Randomize Texture")
82
+ upload_image = gr.Image(
83
+ label="Upload Image",
84
+ tool="editor",
85
+ type="numpy"
86
+ )
87
 
88
  # Update texture when any slider changes
89
  for slider in sliders:
 
100
  outputs=[*sliders, output_image]
101
  )
102
 
103
+ # Update sliders and image based on uploaded image
104
+ upload_image.change(
105
+ fn=on_image_upload,
106
+ inputs=upload_image,
107
+ outputs=[*sliders, output_image]
108
+ )
109
+
110
  demo.launch()