Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,13 @@ import gradio as gr
|
|
2 |
from atproto import Client
|
3 |
from atproto_client.exceptions import BadRequestError
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def get_did_from_handle(handle: str) -> str:
|
6 |
"""
|
7 |
Get the DID for a given Bluesky handle.
|
@@ -12,8 +19,14 @@ def get_did_from_handle(handle: str) -> str:
|
|
12 |
Returns:
|
13 |
str: Success or error message
|
14 |
"""
|
15 |
-
#
|
16 |
-
handle = handle
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Initialize client
|
19 |
client = Client()
|
@@ -23,7 +36,11 @@ def get_did_from_handle(handle: str) -> str:
|
|
23 |
response = client.resolve_handle(handle)
|
24 |
return f"DID: {response.did}"
|
25 |
except BadRequestError as e:
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
except Exception as e:
|
28 |
return f"Error: {str(e)}"
|
29 |
|
@@ -34,7 +51,7 @@ demo = gr.Interface(
|
|
34 |
gr.Textbox(
|
35 |
label="Enter Bluesky Handle",
|
36 |
placeholder="username.bsky.social",
|
37 |
-
info="Enter a Bluesky handle to get its DID"
|
38 |
)
|
39 |
],
|
40 |
outputs=gr.Textbox(label="Result"),
|
|
|
2 |
from atproto import Client
|
3 |
from atproto_client.exceptions import BadRequestError
|
4 |
|
5 |
+
def clean_handle(handle: str) -> str:
|
6 |
+
"""Clean the handle by removing special characters and whitespace."""
|
7 |
+
# Remove @ symbol, whitespace, and any invisible characters
|
8 |
+
handle = ''.join(char for char in handle if char.isprintable())
|
9 |
+
handle = handle.strip().replace('@', '').strip()
|
10 |
+
return handle
|
11 |
+
|
12 |
def get_did_from_handle(handle: str) -> str:
|
13 |
"""
|
14 |
Get the DID for a given Bluesky handle.
|
|
|
19 |
Returns:
|
20 |
str: Success or error message
|
21 |
"""
|
22 |
+
# Clean the handle
|
23 |
+
handle = clean_handle(handle)
|
24 |
+
|
25 |
+
if not handle:
|
26 |
+
return "Error: Please enter a handle"
|
27 |
+
|
28 |
+
if not handle.endswith('.bsky.social'):
|
29 |
+
return "Error: Handle must end with .bsky.social"
|
30 |
|
31 |
# Initialize client
|
32 |
client = Client()
|
|
|
36 |
response = client.resolve_handle(handle)
|
37 |
return f"DID: {response.did}"
|
38 |
except BadRequestError as e:
|
39 |
+
# Add debugging information
|
40 |
+
return (f"Error processing handle: '{handle}'\n"
|
41 |
+
f"Length: {len(handle)}\n"
|
42 |
+
f"Characters (for debugging): {[ord(c) for c in handle]}\n"
|
43 |
+
f"Original error: {str(e)}")
|
44 |
except Exception as e:
|
45 |
return f"Error: {str(e)}"
|
46 |
|
|
|
51 |
gr.Textbox(
|
52 |
label="Enter Bluesky Handle",
|
53 |
placeholder="username.bsky.social",
|
54 |
+
info="Enter a Bluesky handle to get its DID (without the @ symbol)"
|
55 |
)
|
56 |
],
|
57 |
outputs=gr.Textbox(label="Result"),
|