giorgio-caparvi commited on
Commit
b05de99
·
1 Parent(s): f1218c5

retrieving url

Browse files
Files changed (2) hide show
  1. api/app.py +19 -6
  2. api/templates/index.html +20 -0
api/app.py CHANGED
@@ -1,4 +1,4 @@
1
- from flask import Flask, render_template, send_from_directory, send_file
2
  import subprocess
3
  import os
4
  import io
@@ -14,8 +14,26 @@ image_filename = '03191_00.jpg'
14
 
15
  @app.route('/')
16
  def index():
 
 
 
 
 
 
 
17
  return render_template('index.html')
18
 
 
 
 
 
 
 
 
 
 
 
 
19
  @app.route('/generate-design', methods=['POST'])
20
  def generate_design():
21
 
@@ -67,10 +85,5 @@ def generate_design():
67
  except Exception as e:
68
  return str(e), 500
69
 
70
- # Route per servire l'immagine generata
71
- @app.route('/api/output/generato_paired_paired/images/<filename>')
72
- def serve_image(filename):
73
- return send_from_directory(output_dir, filename)
74
-
75
  if __name__ == '__main__':
76
  app.run(host='0.0.0.0', port=7860)
 
1
+ from flask import Flask, render_template, send_from_directory, send_file, request
2
  import subprocess
3
  import os
4
  import io
 
14
 
15
  @app.route('/')
16
  def index():
17
+
18
+ # Extract the full URL where the current request was made
19
+ full_url = request.url
20
+
21
+ # Log the current endpoint to the server logs
22
+ print(f"Current Endpoint: {full_url}")
23
+
24
  return render_template('index.html')
25
 
26
+ @app.route('/current-endpoint', methods=['GET'])
27
+ def current_endpoint():
28
+ # Extract the full URL where the current request was made
29
+ full_url = request.url
30
+
31
+ # Log the current endpoint to the server logs
32
+ print(f"Current Endpoint: {full_url}")
33
+
34
+ # Return the current URL to the client
35
+ return f"Current Endpoint: {full_url}"
36
+
37
  @app.route('/generate-design', methods=['POST'])
38
  def generate_design():
39
 
 
85
  except Exception as e:
86
  return str(e), 500
87
 
 
 
 
 
 
88
  if __name__ == '__main__':
89
  app.run(host='0.0.0.0', port=7860)
api/templates/index.html CHANGED
@@ -26,6 +26,19 @@
26
  alert("Failed to execute the command.");
27
  });
28
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  </script>
30
  </head>
31
  <body>
@@ -40,5 +53,12 @@
40
  <a id="download-button" href="/api/output/generato_paired_paired/images/03191_00.jpg" download style="display:none;">
41
  Download Image
42
  </a>
 
 
 
 
 
 
 
43
  </body>
44
  </html>
 
26
  alert("Failed to execute the command.");
27
  });
28
  }
29
+
30
+ function getCurrentEndpoint() {
31
+ fetch('/current-endpoint', { method: 'GET' })
32
+ .then(response => response.text())
33
+ .then(data => {
34
+ // Display the current endpoint URL on the page
35
+ document.getElementById("current-endpoint").innerText = data;
36
+ console.log(data); // Log the current endpoint URL to the console
37
+ })
38
+ .catch(error => {
39
+ console.error("Error:", error);
40
+ });
41
+ }
42
  </script>
43
  </head>
44
  <body>
 
53
  <a id="download-button" href="/api/output/generato_paired_paired/images/03191_00.jpg" download style="display:none;">
54
  Download Image
55
  </a>
56
+
57
+ <br><br>
58
+
59
+ <!-- New Button to Get Current Endpoint -->
60
+ <button id="current-endpoint-button" onclick="getCurrentEndpoint()">Get Current URL</button>
61
+
62
+ <p id="current-endpoint"></p> <!-- Displays the current endpoint -->
63
  </body>
64
  </html>