Dua Rajper commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load API key from .env file
|
| 7 |
+
load_dotenv()
|
| 8 |
+
github_api_key = os.getenv("GITHUB_API_KEY")
|
| 9 |
+
|
| 10 |
+
# Ensure API key is available
|
| 11 |
+
if not github_api_key:
|
| 12 |
+
raise ValueError("GitHub API key is missing. Check your .env file.")
|
| 13 |
+
|
| 14 |
+
# Define a function to fetch GitHub user details
|
| 15 |
+
def get_github_user(username):
|
| 16 |
+
url = f"https://api.github.com/users/{username}"
|
| 17 |
+
headers = {"Authorization": f"token {github_api_key}"}
|
| 18 |
+
|
| 19 |
+
response = requests.get(url, headers=headers)
|
| 20 |
+
|
| 21 |
+
if response.status_code == 200:
|
| 22 |
+
data = response.json()
|
| 23 |
+
return f"User: {data['login']}\nName: {data.get('name', 'N/A')}\nPublic Repos: {data['public_repos']}\nFollowers: {data['followers']}"
|
| 24 |
+
else:
|
| 25 |
+
return f"Error: {response.status_code} - {response.json().get('message', 'Unknown error')}"
|
| 26 |
+
|
| 27 |
+
# Create Gradio UI
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=get_github_user,
|
| 30 |
+
inputs=gr.Textbox(label="GitHub Username", placeholder="Enter GitHub username"),
|
| 31 |
+
outputs="text",
|
| 32 |
+
title="GitHub User Info Fetcher",
|
| 33 |
+
description="Enter a GitHub username to fetch profile details.",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Launch the app
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
iface.launch()
|