Spaces:
Sleeping
Sleeping
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,38 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
load_dotenv()
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
client = OpenAI(api_key=api_key)
|
| 18 |
-
|
| 19 |
-
# Define chatbot function
|
| 20 |
-
def chatbot(prompt):
|
| 21 |
-
try:
|
| 22 |
-
response = client.chat.completions.create(
|
| 23 |
-
model="gpt-4o",
|
| 24 |
-
messages=[
|
| 25 |
-
{"role": "system", "content": "You are a helpful assistant."},
|
| 26 |
-
{"role": "user", "content": prompt},
|
| 27 |
-
]
|
| 28 |
-
)
|
| 29 |
-
return response.choices[0].message.content
|
| 30 |
-
except Exception as e:
|
| 31 |
-
return f"Error: {str(e)}"
|
| 32 |
-
|
| 33 |
-
# Create Gradio interface
|
| 34 |
iface = gr.Interface(
|
| 35 |
-
fn=
|
| 36 |
-
inputs=gr.Textbox(
|
| 37 |
outputs="text",
|
| 38 |
-
title="
|
| 39 |
-
description="
|
| 40 |
-
theme="compact",
|
| 41 |
)
|
| 42 |
|
| 43 |
-
# Launch
|
| 44 |
if __name__ == "__main__":
|
| 45 |
iface.launch()
|
|
|
|
| 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()
|