gaur3009 commited on
Commit
299e3a2
·
verified ·
1 Parent(s): 45a83bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -31
app.py CHANGED
@@ -44,51 +44,29 @@ def combine_images(dress_image, design_image, position, size):
44
 
45
  def interface():
46
  with gr.Blocks() as demo:
47
- gr.Markdown("## Image Editor with Drag-and-Drop")
48
  dress_image = gr.Image(type="pil", label="Upload Dress Image")
49
- design_image = gr.Image(type="pil", label="Upload Design Image", tool="editor") # Editor tool for resizing
50
-
51
  position = gr.Textbox(placeholder="Enter position as x,y", value="100,100", label="Position")
52
  size = gr.Textbox(placeholder="Enter size as width,height", value="200,200", label="Size")
53
-
54
  btn = gr.Button("Fit Design")
55
  output = gr.Image(type="pil", label="Final Output")
56
 
57
- # Gradio button click function
58
  btn.click(
59
  combine_images,
60
  inputs=[dress_image, design_image, position, size],
61
  outputs=output
62
  )
63
 
64
- # Inject JavaScript for drag-and-drop functionality
65
  gr.HTML("""
66
  <script>
67
- function initDragAndDrop() {
68
- const designImg = document.querySelector('img[data-name="design_image"]');
69
- let startX, startY, initialX, initialY;
70
-
71
- designImg.addEventListener('mousedown', (e) => {
72
- startX = e.clientX;
73
- startY = e.clientY;
74
- initialX = designImg.offsetLeft;
75
- initialY = designImg.offsetTop;
76
-
77
- document.onmousemove = (e) => {
78
- const dx = e.clientX - startX;
79
- const dy = e.clientY - startY;
80
- designImg.style.position = 'absolute';
81
- designImg.style.left = (initialX + dx) + 'px';
82
- designImg.style.top = (initialY + dy) + 'px';
83
- }
84
- });
85
-
86
- document.onmouseup = () => {
87
- document.onmousemove = document.onmouseup = null;
88
- }
89
- }
90
-
91
- window.onload = initDragAndDrop;
92
  </script>
93
  """)
94
 
 
44
 
45
  def interface():
46
  with gr.Blocks() as demo:
47
+ gr.Markdown("## Image Editor with Basic Interaction")
48
  dress_image = gr.Image(type="pil", label="Upload Dress Image")
49
+ design_image = gr.Image(type="pil", label="Upload Design Image")
50
+
51
  position = gr.Textbox(placeholder="Enter position as x,y", value="100,100", label="Position")
52
  size = gr.Textbox(placeholder="Enter size as width,height", value="200,200", label="Size")
53
+
54
  btn = gr.Button("Fit Design")
55
  output = gr.Image(type="pil", label="Final Output")
56
 
57
+ # Button click function
58
  btn.click(
59
  combine_images,
60
  inputs=[dress_image, design_image, position, size],
61
  outputs=output
62
  )
63
 
64
+ # Add JavaScript for additional interactivity (basic example)
65
  gr.HTML("""
66
  <script>
67
+ // JavaScript code for drag-and-drop functionality
68
+ // This code needs to be customized based on how images are rendered
69
+ // and will likely require additional adjustments.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  </script>
71
  """)
72