Spaces:
Sleeping
Sleeping
| 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() | |