| import os |
| import gradio as gr |
| import requests |
| from dotenv import load_dotenv |
|
|
| |
| load_dotenv() |
| github_api_key = os.getenv("GITHUB_API_KEY") |
|
|
| |
| if not github_api_key: |
| raise ValueError("GitHub API key is missing. Check your .env file.") |
|
|
| |
| 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')}" |
|
|
| |
| 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.", |
| ) |
|
|
| |
| if __name__ == "__main__": |
| iface.launch() |
|
|