|
The error you're encountering is due to the `HfApi` class not having a `get_user_from_username` method, as this method does not exist in the Hugging Face Hub's Python API. |
|
|
|
Instead, you can retrieve user information by searching for models or datasets associated with a specific user and then extracting relevant information, like the Twitter handle, from the metadata. However, direct user information retrieval might not be supported via the Hugging Face Hub API. |
|
|
|
Here’s an alternative approach using the available methods: |
|
|
|
```python |
|
import streamlit as st |
|
from huggingface_hub import HfApi |
|
import pandas as pd |
|
|
|
|
|
default_users = { |
|
"users": [ |
|
"rogerxavier", "jonatasgrosman", "kenshinn", "Csplk", "DavidVivancos", |
|
"cdminix", "Jaward", "TuringsSolutions", "Severian", "Wauplin", |
|
"phosseini", "Malikeh1375", "gokaygokay", "MoritzLaurer", "mrm8488", |
|
"TheBloke", "lhoestq", "xw-eric", "Paul", "Muennighoff", |
|
"ccdv", "haonan-li", "chansung", "lukaemon", "hails", |
|
"pharmapsychotic", "KingNish", "merve", "ameerazam08", "ashleykleynhans" |
|
] |
|
} |
|
|
|
def get_twitter_link(username): |
|
api = HfApi() |
|
try: |
|
|
|
models = api.list_models(author=username) |
|
if models: |
|
for model in models: |
|
|
|
twitter = model.cardData.get('social_media', {}).get('twitter') |
|
if twitter: |
|
return f"https://twitter.com/{twitter}" |
|
else: |
|
st.warning(f"No models found for {username}") |
|
except Exception as e: |
|
st.error(f"Error fetching info for {username}: {str(e)}") |
|
return None |
|
|
|
st.title("Hugging Face to Twitter Link Generator") |
|
|
|
|
|
default_users_str = "\n".join(default_users["users"]) |
|
|
|
|
|
usernames = st.text_area("Enter Hugging Face usernames (one per line):", value=default_users_str, height=300) |
|
|
|
if st.button("Generate Twitter Links"): |
|
if usernames: |
|
username_list = [username.strip() for username in usernames.split('\n') if username.strip()] |
|
results = [] |
|
|
|
progress_bar = st.progress(0) |
|
for i, username in enumerate(username_list): |
|
twitter_link = get_twitter_link(username) |
|
results.append({"Hugging Face": username, "Twitter Link": twitter_link}) |
|
progress_bar.progress((i + 1) / len(username_list)) |
|
|
|
df = pd.DataFrame(results) |
|
st.dataframe(df) |
|
|
|
|
|
markdown_links = "" |
|
for _, row in df.iterrows(): |
|
if row['Twitter Link']: |
|
markdown_links += f"- [{row['Hugging Face']}]({row['Twitter Link']})\n" |
|
else: |
|
markdown_links += f"- {row['Hugging Face']} (No Twitter link found)\n" |
|
|
|
st.markdown("### Twitter Profile Links") |
|
st.markdown(markdown_links) |
|
else: |
|
st.warning("Please enter at least one username.") |
|
|
|
st.sidebar.markdown(""" |
|
## How to use: |
|
1. The text area is pre-filled with a list of Hugging Face usernames. You can edit this list or add more usernames. |
|
2. Click 'Generate Twitter Links'. |
|
3. View the results in the table and as clickable links. |
|
4. The progress bar shows the status of link generation. |
|
""") |
|
``` |
|
|