Spaces:
Runtime error
Runtime error
measmonysuon
commited on
Commit
•
d0ce7b4
1
Parent(s):
92d32dc
Update app.py
Browse files
app.py
CHANGED
@@ -23,9 +23,6 @@ DEFAULT_STYLE = "3840 x 2160"
|
|
23 |
logging.basicConfig(level=logging.INFO)
|
24 |
logger = logging.getLogger(__name__)
|
25 |
|
26 |
-
# Initialize database
|
27 |
-
db_path = 'C:/Users/Administrator/Desktop/TGBoot/photo2prompt_db/users.db'
|
28 |
-
|
29 |
def generate_image(prompt, resolution_key, style=DEFAULT_STYLE):
|
30 |
resolution = resolutions.get(resolution_key, (1024, 1024))
|
31 |
width, height = resolution
|
@@ -63,7 +60,7 @@ def update_user_points(username, points):
|
|
63 |
|
64 |
def notify_webhook(username):
|
65 |
"""Notify the webhook server about the points update."""
|
66 |
-
webhook_url = "
|
67 |
payload = {'username': username, 'points': 10} # Adjust payload as necessary
|
68 |
try:
|
69 |
response = requests.post(webhook_url, json=payload)
|
@@ -74,7 +71,7 @@ def notify_webhook(username):
|
|
74 |
|
75 |
def get_user_points(username):
|
76 |
"""Retrieve user points from the Flask server."""
|
77 |
-
webhook_url = "
|
78 |
params = {'username': username}
|
79 |
try:
|
80 |
response = requests.get(webhook_url, params=params)
|
@@ -89,8 +86,7 @@ def extract_username_from_url(url):
|
|
89 |
params = parse_qs(parsed_url.query)
|
90 |
return params.get('username', ["Guest"])[0]
|
91 |
|
92 |
-
def gradio_interface(prompt, resolution_key,
|
93 |
-
username = extract_username_from_url(url)
|
94 |
result = generate_image(prompt, resolution_key)
|
95 |
|
96 |
if result and result[0]:
|
@@ -135,8 +131,8 @@ def create_gradio_interface():
|
|
135 |
points_output = gr.Textbox(label="User Points", placeholder="User points will be displayed here", interactive=False)
|
136 |
|
137 |
# Hidden textbox to hold the username
|
138 |
-
username_input = gr.Textbox(visible=False, default="Guest"
|
139 |
-
|
140 |
# Set up interaction
|
141 |
generate_button.click(
|
142 |
fn=lambda prompt, resolution_key, username: gradio_interface(prompt, resolution_key, username),
|
|
|
23 |
logging.basicConfig(level=logging.INFO)
|
24 |
logger = logging.getLogger(__name__)
|
25 |
|
|
|
|
|
|
|
26 |
def generate_image(prompt, resolution_key, style=DEFAULT_STYLE):
|
27 |
resolution = resolutions.get(resolution_key, (1024, 1024))
|
28 |
width, height = resolution
|
|
|
60 |
|
61 |
def notify_webhook(username):
|
62 |
"""Notify the webhook server about the points update."""
|
63 |
+
webhook_url = f"{webhook_server}/update_points"
|
64 |
payload = {'username': username, 'points': 10} # Adjust payload as necessary
|
65 |
try:
|
66 |
response = requests.post(webhook_url, json=payload)
|
|
|
71 |
|
72 |
def get_user_points(username):
|
73 |
"""Retrieve user points from the Flask server."""
|
74 |
+
webhook_url = f"{webhook_server}/get_points"
|
75 |
params = {'username': username}
|
76 |
try:
|
77 |
response = requests.get(webhook_url, params=params)
|
|
|
86 |
params = parse_qs(parsed_url.query)
|
87 |
return params.get('username', ["Guest"])[0]
|
88 |
|
89 |
+
def gradio_interface(prompt, resolution_key, username):
|
|
|
90 |
result = generate_image(prompt, resolution_key)
|
91 |
|
92 |
if result and result[0]:
|
|
|
131 |
points_output = gr.Textbox(label="User Points", placeholder="User points will be displayed here", interactive=False)
|
132 |
|
133 |
# Hidden textbox to hold the username
|
134 |
+
username_input = gr.Textbox(visible=False, default="Guest")
|
135 |
+
|
136 |
# Set up interaction
|
137 |
generate_button.click(
|
138 |
fn=lambda prompt, resolution_key, username: gradio_interface(prompt, resolution_key, username),
|