Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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.
|
| 8 |
+
|
| 9 |
+
Args:
|
| 10 |
+
handle (str): Bluesky handle (e.g., 'username.bsky.social')
|
| 11 |
+
|
| 12 |
+
Returns:
|
| 13 |
+
str: Success or error message
|
| 14 |
+
"""
|
| 15 |
+
# Remove @ symbol if present
|
| 16 |
+
handle = handle.strip().replace('@', '')
|
| 17 |
+
|
| 18 |
+
# Initialize client
|
| 19 |
+
client = Client()
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
# Attempt to resolve handle
|
| 23 |
+
response = client.resolve_handle(handle)
|
| 24 |
+
return f"DID: {response.did}"
|
| 25 |
+
except BadRequestError as e:
|
| 26 |
+
return f"Error: Invalid handle format. Please use format 'username.bsky.social'"
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return f"Error: {str(e)}"
|
| 29 |
+
|
| 30 |
+
# Create Gradio interface
|
| 31 |
+
demo = gr.Interface(
|
| 32 |
+
fn=get_did_from_handle,
|
| 33 |
+
inputs=[
|
| 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"),
|
| 41 |
+
title="Bluesky DID Lookup",
|
| 42 |
+
description="Look up the DID (Decentralized Identifier) for any Bluesky handle. Enter a handle in the format 'username.bsky.social'.",
|
| 43 |
+
examples=[
|
| 44 |
+
["atproto.bsky.social"],
|
| 45 |
+
["bsky.app"],
|
| 46 |
+
],
|
| 47 |
+
theme=gr.themes.Soft()
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
demo.launch()
|