Pranesh64 commited on
Commit
1cc8888
Β·
verified Β·
1 Parent(s): aeff7b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -0
app.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+ from datetime import datetime
5
+ from dotenv import load_dotenv
6
+
7
+ load_dotenv()
8
+
9
+ GITHUB_CLIENT_ID = os.getenv("GITHUB_CLIENT_ID")
10
+ GITHUB_CLIENT_SECRET = os.getenv("GITHUB_CLIENT_SECRET")
11
+
12
+ GITHUB_GRAPHQL = "https://api.github.com/graphql"
13
+
14
+ def github_graphql(query, token):
15
+ headers = {
16
+ "Authorization": f"Bearer {token}",
17
+ "Content-Type": "application/json"
18
+ }
19
+ r = requests.post(GITHUB_GRAPHQL, json={"query": query}, headers=headers)
20
+ r.raise_for_status()
21
+ return r.json()
22
+
23
+ def fetch_github_wrapped(token):
24
+ query = """
25
+ query {
26
+ viewer {
27
+ login
28
+ contributionsCollection(
29
+ from: "2025-01-01T00:00:00Z",
30
+ to: "2025-12-31T23:59:59Z"
31
+ ) {
32
+ contributionCalendar {
33
+ totalContributions
34
+ }
35
+ totalCommitContributions
36
+ totalPullRequestContributions
37
+ totalIssueContributions
38
+ }
39
+ repositories(first: 100, ownerAffiliations: OWNER, orderBy: {field: STARGAZERS, direction: DESC}) {
40
+ nodes {
41
+ name
42
+ stargazerCount
43
+ primaryLanguage {
44
+ name
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+ """
51
+
52
+ data = github_graphql(query, token)["data"]["viewer"]
53
+
54
+ repos = data["repositories"]["nodes"]
55
+ languages = {}
56
+
57
+ for r in repos:
58
+ if r["primaryLanguage"]:
59
+ lang = r["primaryLanguage"]["name"]
60
+ languages[lang] = languages.get(lang, 0) + 1
61
+
62
+ top_language = max(languages, key=languages.get) if languages else "Unknown"
63
+ top_repo = repos[0]["name"] if repos else "None"
64
+
65
+ return {
66
+ "username": data["login"],
67
+ "commits": data["contributionsCollection"]["totalCommitContributions"],
68
+ "prs": data["contributionsCollection"]["totalPullRequestContributions"],
69
+ "issues": data["contributionsCollection"]["totalIssueContributions"],
70
+ "total": data["contributionsCollection"]["contributionCalendar"]["totalContributions"],
71
+ "top_language": top_language,
72
+ "top_repo": top_repo
73
+ }
74
+
75
+ def render_wrapped(stats):
76
+ return f"""
77
+ <div style="
78
+ font-family: Poppins, sans-serif;
79
+ padding: 40px;
80
+ background: linear-gradient(135deg,#0f2027,#203a43,#2c5364);
81
+ color: white;
82
+ border-radius: 20px;
83
+ max-width: 800px;
84
+ margin: auto;
85
+ ">
86
+ <h1 style="font-size: 3em; text-align:center;">πŸŽ‰ GitHub Wrapped 2025</h1>
87
+ <h2 style="text-align:center;">@{stats['username']}</h2>
88
+
89
+ <div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:20px;margin-top:40px;">
90
+ <div class="card">πŸ”₯ {stats['total']} Contributions</div>
91
+ <div class="card">πŸ’» {stats['commits']} Commits</div>
92
+ <div class="card">πŸ” {stats['prs']} PRs</div>
93
+ <div class="card">🐞 {stats['issues']} Issues</div>
94
+ </div>
95
+
96
+ <div style="margin-top:40px;">
97
+ <h3>✨ Your Coding Personality</h3>
98
+ <p><b>Favorite Language:</b> {stats['top_language']}</p>
99
+ <p><b>Most Starred Repo:</b> {stats['top_repo']}</p>
100
+ </div>
101
+
102
+ <p style="text-align:center;margin-top:40px;">
103
+ Keep shipping amazing code in 2026 πŸš€
104
+ </p>
105
+ </div>
106
+
107
+ <style>
108
+ .card {{
109
+ background: rgba(255,255,255,0.15);
110
+ padding: 25px;
111
+ border-radius: 15px;
112
+ font-size: 1.4em;
113
+ text-align: center;
114
+ font-weight: 600;
115
+ backdrop-filter: blur(8px);
116
+ }}
117
+ </style>
118
+ """
119
+
120
+ def wrapped_with_token(token):
121
+ stats = fetch_github_wrapped(token)
122
+ return render_wrapped(stats)
123
+
124
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
125
+ gr.Markdown("## 🎁 GitHub Wrapped 2025")
126
+
127
+ gr.Markdown("""
128
+ πŸ‘‰ Login with GitHub to generate your personalized Wrapped.
129
+ """)
130
+
131
+ token_input = gr.Textbox(
132
+ label="GitHub OAuth Token",
133
+ placeholder="Token is received automatically after OAuth",
134
+ visible=False
135
+ )
136
+
137
+ output = gr.HTML()
138
+
139
+ gr.Button("Generate My GitHub Wrapped πŸš€").click(
140
+ wrapped_with_token,
141
+ inputs=token_input,
142
+ outputs=output
143
+ )
144
+
145
+ demo.launch()