Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from huggingface_hub import HfApi
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
# Default list of Hugging Face usernames
|
6 |
+
default_users = {
|
7 |
+
"users": [
|
8 |
+
"rogerxavier", "jonatasgrosman", "kenshinn", "Csplk", "DavidVivancos",
|
9 |
+
"cdminix", "Jaward", "TuringsSolutions", "Severian", "Wauplin",
|
10 |
+
"phosseini", "Malikeh1375", "gokaygokay", "MoritzLaurer", "mrm8488",
|
11 |
+
"TheBloke", "lhoestq", "xw-eric", "Paul", "Muennighoff",
|
12 |
+
"ccdv", "haonan-li", "chansung", "lukaemon", "hails",
|
13 |
+
"pharmapsychotic", "KingNish", "merve", "ameerazam08", "ashleykleynhans"
|
14 |
+
]
|
15 |
+
}
|
16 |
+
|
17 |
+
def get_twitter_link(username):
|
18 |
+
api = HfApi()
|
19 |
+
try:
|
20 |
+
user_info = api.get_user_from_username(username)
|
21 |
+
twitter = user_info.twitter
|
22 |
+
if twitter:
|
23 |
+
return f"https://twitter.com/{twitter}"
|
24 |
+
except Exception as e:
|
25 |
+
st.error(f"Error fetching info for {username}: {str(e)}")
|
26 |
+
return None
|
27 |
+
|
28 |
+
st.title("Hugging Face to Twitter Link Generator")
|
29 |
+
|
30 |
+
# Convert the default users list to a string
|
31 |
+
default_users_str = "\n".join(default_users["users"])
|
32 |
+
|
33 |
+
# Text area with default list of usernames
|
34 |
+
usernames = st.text_area("Enter Hugging Face usernames (one per line):", value=default_users_str, height=300)
|
35 |
+
|
36 |
+
if st.button("Generate Twitter Links"):
|
37 |
+
if usernames:
|
38 |
+
username_list = [username.strip() for username in usernames.split('\n') if username.strip()]
|
39 |
+
results = []
|
40 |
+
|
41 |
+
progress_bar = st.progress(0)
|
42 |
+
for i, username in enumerate(username_list):
|
43 |
+
twitter_link = get_twitter_link(username)
|
44 |
+
results.append({"Hugging Face": username, "Twitter Link": twitter_link})
|
45 |
+
progress_bar.progress((i + 1) / len(username_list))
|
46 |
+
|
47 |
+
df = pd.DataFrame(results)
|
48 |
+
st.dataframe(df)
|
49 |
+
|
50 |
+
# Generate markdown with hyperlinks
|
51 |
+
markdown_links = ""
|
52 |
+
for _, row in df.iterrows():
|
53 |
+
if row['Twitter Link']:
|
54 |
+
markdown_links += f"- [{row['Hugging Face']}]({row['Twitter Link']})\n"
|
55 |
+
else:
|
56 |
+
markdown_links += f"- {row['Hugging Face']} (No Twitter link found)\n"
|
57 |
+
|
58 |
+
st.markdown("### Twitter Profile Links")
|
59 |
+
st.markdown(markdown_links)
|
60 |
+
else:
|
61 |
+
st.warning("Please enter at least one username.")
|
62 |
+
|
63 |
+
st.sidebar.markdown("""
|
64 |
+
## How to use:
|
65 |
+
1. The text area is pre-filled with a list of Hugging Face usernames. You can edit this list or add more usernames.
|
66 |
+
2. Click 'Generate Twitter Links'.
|
67 |
+
3. View the results in the table and as clickable links.
|
68 |
+
4. The progress bar shows the status of link generation.
|
69 |
+
""")
|