davanstrien's picture
davanstrien HF staff
Create app.py
8eb94c9 verified
raw
history blame
1.43 kB
import gradio as gr
from atproto import Client
from atproto_client.exceptions import BadRequestError
def get_did_from_handle(handle: str) -> str:
"""
Get the DID for a given Bluesky handle.
Args:
handle (str): Bluesky handle (e.g., 'username.bsky.social')
Returns:
str: Success or error message
"""
# Remove @ symbol if present
handle = handle.strip().replace('@', '')
# Initialize client
client = Client()
try:
# Attempt to resolve handle
response = client.resolve_handle(handle)
return f"DID: {response.did}"
except BadRequestError as e:
return f"Error: Invalid handle format. Please use format 'username.bsky.social'"
except Exception as e:
return f"Error: {str(e)}"
# Create Gradio interface
demo = gr.Interface(
fn=get_did_from_handle,
inputs=[
gr.Textbox(
label="Enter Bluesky Handle",
placeholder="username.bsky.social",
info="Enter a Bluesky handle to get its DID"
)
],
outputs=gr.Textbox(label="Result"),
title="Bluesky DID Lookup",
description="Look up the DID (Decentralized Identifier) for any Bluesky handle. Enter a handle in the format 'username.bsky.social'.",
examples=[
["atproto.bsky.social"],
["bsky.app"],
],
theme=gr.themes.Soft()
)
if __name__ == "__main__":
demo.launch()