awacke1 commited on
Commit
c2bed9a
1 Parent(s): 45e7a80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -1,3 +1,10 @@
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from huggingface_hub import HfApi
3
  import pandas as pd
@@ -17,10 +24,16 @@ default_users = {
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
@@ -66,4 +79,5 @@ st.sidebar.markdown("""
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
- """)
 
 
1
+ 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.
2
+
3
+ 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.
4
+
5
+ Here’s an alternative approach using the available methods:
6
+
7
+ ```python
8
  import streamlit as st
9
  from huggingface_hub import HfApi
10
  import pandas as pd
 
24
  def get_twitter_link(username):
25
  api = HfApi()
26
  try:
27
+ # Fetch the models associated with the user
28
+ models = api.list_models(author=username)
29
+ if models:
30
+ for model in models:
31
+ # Try to get the Twitter handle from the first model found
32
+ twitter = model.cardData.get('social_media', {}).get('twitter')
33
+ if twitter:
34
+ return f"https://twitter.com/{twitter}"
35
+ else:
36
+ st.warning(f"No models found for {username}")
37
  except Exception as e:
38
  st.error(f"Error fetching info for {username}: {str(e)}")
39
  return None
 
79
  2. Click 'Generate Twitter Links'.
80
  3. View the results in the table and as clickable links.
81
  4. The progress bar shows the status of link generation.
82
+ """)
83
+ ```