import streamlit as st from huggingface_hub import HfApi import pandas as pd # Default list of Hugging Face usernames 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: user_info = api.get_user_from_username(username) twitter = user_info.twitter if twitter: return f"https://twitter.com/{twitter}" except Exception as e: st.error(f"Error fetching info for {username}: {str(e)}") return None st.title("Hugging Face to Twitter Link Generator") # Convert the default users list to a string default_users_str = "\n".join(default_users["users"]) # Text area with default list of usernames 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) # Generate markdown with hyperlinks 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. """)