Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,6 @@ from urllib.parse import urlparse, parse_qs
|
|
8 |
# Initialize the client for image generation
|
9 |
client_image = Client("mukaist/DALLE-4K")
|
10 |
|
11 |
-
|
12 |
# Define resolutions and default style
|
13 |
resolutions = {
|
14 |
"896x1152": (896, 1152),
|
@@ -45,14 +44,17 @@ def generate_image(prompt, resolution_key, style=DEFAULT_STYLE):
|
|
45 |
logger.error(f"Error generating image: {e}")
|
46 |
return None
|
47 |
|
|
|
|
|
|
|
|
|
48 |
def verify_otp(user_chat_id, otp):
|
49 |
response = requests.post(f"{webhook_server}/verify_otp", json={"user_chat_id": user_chat_id, "otp": otp})
|
50 |
return response.json().get("valid", False)
|
51 |
|
52 |
def retrieve_user_points(user_chat_id, otp):
|
53 |
# Verify OTP via Flask server
|
54 |
-
|
55 |
-
if otp_response.status_code != 200 or not otp_response.json().get('valid'):
|
56 |
return "Invalid or expired OTP. Please request a new OTP."
|
57 |
|
58 |
# Retrieve user points via Flask server
|
@@ -132,6 +134,12 @@ def handle_generate_image(prompt, resolution_key, user_chat_id):
|
|
132 |
return None, "There was an error processing your photo. Please try again later."
|
133 |
return None, "Insufficient points. Please get more points before generating an image."
|
134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
def create_gradio_interface():
|
136 |
with gr.Blocks() as interface:
|
137 |
gr.HTML("""
|
@@ -141,8 +149,12 @@ def create_gradio_interface():
|
|
141 |
|
142 |
user_chat_id_input = gr.Textbox(label="Your UID", placeholder="Your UID")
|
143 |
user_otp_input = gr.Textbox(label="OTP", type="password")
|
144 |
-
points_output = gr.Textbox(label="Your Balances", placeholder="Your Points", interactive=False)
|
145 |
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
get_points_button = gr.Button("Show Your Points")
|
148 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
@@ -155,6 +167,7 @@ def create_gradio_interface():
|
|
155 |
with gr.Row():
|
156 |
user_chat_id_input
|
157 |
points_output
|
|
|
158 |
get_points_button
|
159 |
|
160 |
with gr.Row():
|
@@ -174,6 +187,12 @@ def create_gradio_interface():
|
|
174 |
outputs=[points_output]
|
175 |
)
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
gr.HTML("""
|
178 |
<style>
|
179 |
footer.svelte-1rjryqp {
|
|
|
8 |
# Initialize the client for image generation
|
9 |
client_image = Client("mukaist/DALLE-4K")
|
10 |
|
|
|
11 |
# Define resolutions and default style
|
12 |
resolutions = {
|
13 |
"896x1152": (896, 1152),
|
|
|
44 |
logger.error(f"Error generating image: {e}")
|
45 |
return None
|
46 |
|
47 |
+
def request_otp(user_chat_id):
|
48 |
+
response = requests.post(f"{webhook_server}/request_otp", json={"user_chat_id": user_chat_id})
|
49 |
+
return response.json()
|
50 |
+
|
51 |
def verify_otp(user_chat_id, otp):
|
52 |
response = requests.post(f"{webhook_server}/verify_otp", json={"user_chat_id": user_chat_id, "otp": otp})
|
53 |
return response.json().get("valid", False)
|
54 |
|
55 |
def retrieve_user_points(user_chat_id, otp):
|
56 |
# Verify OTP via Flask server
|
57 |
+
if not verify_otp(user_chat_id, otp):
|
|
|
58 |
return "Invalid or expired OTP. Please request a new OTP."
|
59 |
|
60 |
# Retrieve user points via Flask server
|
|
|
134 |
return None, "There was an error processing your photo. Please try again later."
|
135 |
return None, "Insufficient points. Please get more points before generating an image."
|
136 |
|
137 |
+
def request_otp_and_update_ui(user_chat_id):
|
138 |
+
otp_response = request_otp(user_chat_id)
|
139 |
+
if otp_response.get("success"):
|
140 |
+
return "OTP has been sent to your registered contact."
|
141 |
+
return "Error requesting OTP. Please try again later."
|
142 |
+
|
143 |
def create_gradio_interface():
|
144 |
with gr.Blocks() as interface:
|
145 |
gr.HTML("""
|
|
|
149 |
|
150 |
user_chat_id_input = gr.Textbox(label="Your UID", placeholder="Your UID")
|
151 |
user_otp_input = gr.Textbox(label="OTP", type="password")
|
|
|
152 |
|
153 |
+
with gr.Row():
|
154 |
+
request_otp_button = gr.Button("Request OTP")
|
155 |
+
user_otp_input
|
156 |
+
|
157 |
+
points_output = gr.Textbox(label="Your Balances", placeholder="Your Points", interactive=False)
|
158 |
|
159 |
get_points_button = gr.Button("Show Your Points")
|
160 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...")
|
|
|
167 |
with gr.Row():
|
168 |
user_chat_id_input
|
169 |
points_output
|
170 |
+
request_otp_button
|
171 |
get_points_button
|
172 |
|
173 |
with gr.Row():
|
|
|
187 |
outputs=[points_output]
|
188 |
)
|
189 |
|
190 |
+
request_otp_button.click(
|
191 |
+
fn=request_otp_and_update_ui,
|
192 |
+
inputs=[user_chat_id_input],
|
193 |
+
outputs=[message_output]
|
194 |
+
)
|
195 |
+
|
196 |
gr.HTML("""
|
197 |
<style>
|
198 |
footer.svelte-1rjryqp {
|