File size: 1,211 Bytes
f2d0e2c
 
8288621
f2d0e2c
 
8288621
f2d0e2c
8288621
f2d0e2c
8288621
 
 
f2d0e2c
8288621
 
 
 
 
 
 
 
 
 
 
 
f2d0e2c
8288621
f2d0e2c
8288621
 
f2d0e2c
8288621
 
f2d0e2c
 
8288621
f2d0e2c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import gradio as gr
import requests
from dotenv import load_dotenv

# Load API key from .env file
load_dotenv()
github_api_key = os.getenv("GITHUB_API_KEY")

# Ensure API key is available
if not github_api_key:
    raise ValueError("GitHub API key is missing. Check your .env file.")

# Define a function to fetch GitHub user details
def get_github_user(username):
    url = f"https://api.github.com/users/{username}"
    headers = {"Authorization": f"token {github_api_key}"}
    
    response = requests.get(url, headers=headers)
    
    if response.status_code == 200:
        data = response.json()
        return f"User: {data['login']}\nName: {data.get('name', 'N/A')}\nPublic Repos: {data['public_repos']}\nFollowers: {data['followers']}"
    else:
        return f"Error: {response.status_code} - {response.json().get('message', 'Unknown error')}"

# Create Gradio UI
iface = gr.Interface(
    fn=get_github_user,
    inputs=gr.Textbox(label="GitHub Username", placeholder="Enter GitHub username"),
    outputs="text",
    title="GitHub User Info Fetcher",
    description="Enter a GitHub username to fetch profile details.",
)

# Launch the app
if __name__ == "__main__":
    iface.launch()