jkorstad commited on
Commit
3403bc2
·
verified ·
1 Parent(s): b834a4c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -0
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+ def search_spaces(search_text, category):
5
+ if category == "All Categories":
6
+ spaces_df = df
7
+ else:
8
+ spaces_df = df[df['category'] == category]
9
+
10
+ if search_text:
11
+ spaces_df = spaces_df[spaces_df['title'].str.lower().str.contains(search_text.lower())]
12
+
13
+ spaces = spaces_df.nlargest(20, 'likes')[['title', 'likes', 'url', 'category']]
14
+
15
+ # Get category stats
16
+ total_spaces = len(spaces_df)
17
+ total_likes = spaces_df['likes'].sum()
18
+
19
+ # Format the results as HTML with clickable links and stats
20
+ html_content = f"""
21
+ <div style='margin-bottom: 20px; padding: 10px; background-color: #f5f5f5; border-radius: 5px;'>
22
+ <h3>Statistics:</h3>
23
+ <p>Total Spaces: {total_spaces}</p>
24
+ <p>Total Likes: {total_likes:,}</p>
25
+ </div>
26
+ <div style='max-height: 500px; overflow-y: auto;'>
27
+ """
28
+
29
+ for _, row in spaces.iterrows():
30
+ html_content += f"""
31
+ <div style='margin: 10px; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background-color: white;'>
32
+ <h3><a href='{row['url']}' target='_blank' style='color: #2196F3; text-decoration: none;'>{row['title']}</a></h3>
33
+ <p>Category: {row['category']}</p>
34
+ <p>❤️ {row['likes']:,} likes</p>
35
+ </div>
36
+ """
37
+ html_content += "</div>"
38
+ return html_content
39
+
40
+ # Create the Gradio interface
41
+ def create_app():
42
+ with gr.Blocks(title="Hugging Face Spaces Explorer", theme=gr.themes.Soft()) as app:
43
+ gr.Markdown("""
44
+ # 🤗 Hugging Face Spaces Explorer
45
+ Explore and discover popular Hugging Face Spaces by category
46
+ """)
47
+
48
+ with gr.Row():
49
+ with gr.Column(scale=1):
50
+ # Category selection
51
+ category_dropdown = gr.Dropdown(
52
+ choices=["All Categories"] + sorted(df['category'].unique()),
53
+ label="Select Category",
54
+ value="All Categories"
55
+ )
56
+ # Search box
57
+ search_input = gr.Textbox(
58
+ label="Search Spaces",
59
+ placeholder="Enter search terms..."
60
+ )
61
+
62
+ # Display area for spaces
63
+ spaces_display = gr.HTML(value=search_spaces("", "All Categories"))
64
+
65
+ # Update display when category or search changes
66
+ category_dropdown.change(
67
+ fn=search_spaces,
68
+ inputs=[search_input, category_dropdown],
69
+ outputs=spaces_display
70
+ )
71
+ search_input.change(
72
+ fn=search_spaces,
73
+ inputs=[search_input, category_dropdown],
74
+ outputs=spaces_display
75
+ )
76
+
77
+ return app
78
+
79
+ # Launch the app
80
+ app = create_app()
81
+ app.launch(share=True)