lelafav502 commited on
Commit
5635991
·
verified ·
1 Parent(s): 840498c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -10
app.py CHANGED
@@ -10,9 +10,6 @@ def send_text2image_request(prompt, ratio, style, uuid_value, token):
10
  if not url:
11
  return "Error: API URL not set in environment secrets."
12
 
13
- # Print the URL for debugging purposes
14
-
15
-
16
  # Define the headers with the required values
17
  headers = {
18
  "Uid": uuid_value, # Using the provided UUID
@@ -47,9 +44,6 @@ def send_image2image_request(image, ratio, style, uuid_value, token):
47
  if not url:
48
  return "Error: API URL not set in environment secrets."
49
 
50
- # Print the URL for debugging purposes
51
-
52
-
53
  # Define the headers with the required values
54
  headers = {
55
  "Uid": uuid_value, # Using the provided UUID
@@ -72,8 +66,7 @@ def send_image2image_request(image, ratio, style, uuid_value, token):
72
  if style and style != "0":
73
  data["style_id"] = style
74
 
75
-
76
- response = requests.post(url, headers=headers, data=data, files=files)
77
 
78
  # Return the response text or any relevant information
79
  if response.status_code == 200:
@@ -81,7 +74,27 @@ def send_image2image_request(image, ratio, style, uuid_value, token):
81
  else:
82
  return f"Error: {response.status_code} - {response.text}"
83
 
84
- # Gradio interface with tabs for Text-to-Image and Image-to-Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  def create_interface():
86
  with gr.Blocks() as demo:
87
  with gr.Tab("Text to Image"):
@@ -109,7 +122,16 @@ def create_interface():
109
  # Bind the image-to-image function to the interface
110
  img_submit_button = gr.Button("Generate Image")
111
  img_submit_button.click(send_image2image_request, inputs=[img_url, img_ratio, img_style, img_uuid, img_token], outputs=img_output)
112
-
 
 
 
 
 
 
 
 
 
113
  return demo
114
 
115
  # Launch the Gradio interface
 
10
  if not url:
11
  return "Error: API URL not set in environment secrets."
12
 
 
 
 
13
  # Define the headers with the required values
14
  headers = {
15
  "Uid": uuid_value, # Using the provided UUID
 
44
  if not url:
45
  return "Error: API URL not set in environment secrets."
46
 
 
 
 
47
  # Define the headers with the required values
48
  headers = {
49
  "Uid": uuid_value, # Using the provided UUID
 
66
  if style and style != "0":
67
  data["style_id"] = style
68
 
69
+ response = requests.post(url, headers=headers, data=data)
 
70
 
71
  # Return the response text or any relevant information
72
  if response.status_code == 200:
 
74
  else:
75
  return f"Error: {response.status_code} - {response.text}"
76
 
77
+ # Function to get the Upload URL from Firebase
78
+ def get_upload_url(uuid_value):
79
+ # The URL to send the request to
80
+ firebase_url = 'https://firebasestorage.googleapis.com/v0/b/hardstone_img_us/o?name=umagic_crop%2Fupload%2F2024-11-17%2F{}.jpg&uploadType=resumable'.format(uuid_value)
81
+
82
+ # Define the headers with the required values
83
+ headers = {
84
+ "Authorization": "Bearer YOUR_ACCESS_TOKEN", # Replace with the correct Bearer Token if needed
85
+ "Content-Type": "application/json"
86
+ }
87
+
88
+ # Sending GET request to Firebase Storage
89
+ response = requests.get(firebase_url, headers=headers)
90
+
91
+ # Return the response text or any relevant information
92
+ if response.status_code == 200:
93
+ return response.json() # You can return JSON data if that's the expected response format
94
+ else:
95
+ return f"Error: {response.status_code} - {response.text}"
96
+
97
+ # Gradio interface with tabs for Text-to-Image, Image-to-Image, and Get Upload URL
98
  def create_interface():
99
  with gr.Blocks() as demo:
100
  with gr.Tab("Text to Image"):
 
122
  # Bind the image-to-image function to the interface
123
  img_submit_button = gr.Button("Generate Image")
124
  img_submit_button.click(send_image2image_request, inputs=[img_url, img_ratio, img_style, img_uuid, img_token], outputs=img_output)
125
+
126
+ with gr.Tab("Get Upload URL"):
127
+ # Inputs for Get Upload URL
128
+ uuid_input = gr.Textbox(label="UUID ID") # UUID for getting upload URL
129
+ upload_url_output = gr.Textbox() # Output for the upload URL response
130
+
131
+ # Bind the get_upload_url function to the interface
132
+ upload_submit_button = gr.Button("Get Upload URL")
133
+ upload_submit_button.click(get_upload_url, inputs=[uuid_input], outputs=upload_url_output)
134
+
135
  return demo
136
 
137
  # Launch the Gradio interface