davanstrien HF staff commited on
Commit
cad28e4
β€’
1 Parent(s): c5a4ed0

try and then clean and fail

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -14,33 +14,33 @@ def get_did_from_handle(handle: str) -> str:
14
  Get the DID for a given Bluesky handle.
15
 
16
  Args:
17
- handle (str): Bluesky handle (e.g., 'username.bsky.social')
18
 
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()
33
 
 
34
  try:
35
- # Attempt to resolve handle
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,18 +51,20 @@ demo = gr.Interface(
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"),
58
  title="Bluesky DID Lookup",
59
- description="Look up the DID (Decentralized Identifier) for any Bluesky handle. Enter a handle in the format 'username.bsky.social'.<br><br>Built by <a href='https://bsky.app/profile/danielvanstrien.bsky.social'>@danielvanstrien.bsky.social</a><br>Part of <a href='https://huggingface.co/bluesky-community'>Bluesky Community</a>",
60
  examples=[
61
  ["atproto.bsky.social"],
62
  ["bsky.app"],
63
  ["danielvanstrien.bsky.social"],
 
64
  ],
65
  theme=gr.themes.Default(),
 
66
  )
67
 
68
  if __name__ == "__main__":
 
14
  Get the DID for a given Bluesky handle.
15
 
16
  Args:
17
+ handle (str): Bluesky handle (any valid format)
18
 
19
  Returns:
20
  str: Success or error message
21
  """
 
 
 
22
  if not handle:
23
  return "Error: Please enter a handle"
24
 
 
 
 
25
  # Initialize client
26
  client = Client()
27
 
28
+ # First try: raw input
29
  try:
 
30
  response = client.resolve_handle(handle)
31
  return f"DID: {response.did}"
32
+ except BadRequestError:
33
+ # Second try: cleaned input
34
+ try:
35
+ cleaned_handle = clean_handle(handle)
36
+ if cleaned_handle != handle: # Only try if cleaning actually changed something
37
+ response = client.resolve_handle(cleaned_handle)
38
+ return f"DID: {response.did}"
39
+ except BadRequestError as e:
40
+ return (f"Error: Could not resolve handle. Please check the format.\n"
41
+ f"Tried both '{handle}' and '{cleaned_handle}'")
42
+ except Exception as e:
43
+ return f"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 (with or without @ symbol)"
55
  )
56
  ],
57
  outputs=gr.Textbox(label="Result"),
58
  title="Bluesky DID Lookup",
59
+ description="Look up the DID (Decentralized Identifier) for any Bluesky handle.<br><br>Built by <a href='https://bsky.app/profile/danielvanstrien.bsky.social'>@danielvanstrien.bsky.social</a><br>Part of <a href='https://huggingface.co/bluesky-community'>Bluesky Community</a>",
60
  examples=[
61
  ["atproto.bsky.social"],
62
  ["bsky.app"],
63
  ["danielvanstrien.bsky.social"],
64
+ ["@jay.bsky.team"],
65
  ],
66
  theme=gr.themes.Default(),
67
+ allow_flagging="never"
68
  )
69
 
70
  if __name__ == "__main__":