Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,24 +6,6 @@ import requests
|
|
6 |
# Hugging Face Inference Client
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
9 |
-
# GitHub API details
|
10 |
-
GITHUB_USERNAME = "YOUR_USERNAME"
|
11 |
-
GITHUB_REPOSITORY = "YOUR_REPOSITORY"
|
12 |
-
GITHUB_API_TOKEN = os.getenv("GITHUB_API_TOKEN")
|
13 |
-
|
14 |
-
# Function to fetch GitHub issues
|
15 |
-
def fetch_github_issues():
|
16 |
-
url = f"https://api.github.com/repos/{GITHUB_USERNAME}/{GITHUB_REPOSITORY}/issues"
|
17 |
-
headers = {
|
18 |
-
"Authorization": f"Bearer {GITHUB_API_TOKEN}",
|
19 |
-
"Accept": "application/vnd.github.v3+json"
|
20 |
-
}
|
21 |
-
response = requests.get(url, headers=headers)
|
22 |
-
if response.status_code == 200:
|
23 |
-
return response.json()
|
24 |
-
else:
|
25 |
-
raise Exception(f"Error fetching issues: {response.status_code}")
|
26 |
-
|
27 |
# Function to analyze issues and provide solutions
|
28 |
def analyze_issues(issue_text, model_name):
|
29 |
nlp = pipeline("text-generation", model=model_name)
|
@@ -38,7 +20,13 @@ def respond(
|
|
38 |
max_tokens,
|
39 |
temperature,
|
40 |
top_p,
|
|
|
|
|
|
|
41 |
):
|
|
|
|
|
|
|
42 |
messages = [{"role": "system", "content": system_message}]
|
43 |
|
44 |
for val in history:
|
@@ -48,22 +36,46 @@ def respond(
|
|
48 |
messages.append({"role": "assistant", "content": val[1]})
|
49 |
|
50 |
if message.startswith("/github"):
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
elif message.isdigit():
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
else:
|
68 |
messages.append({"role": "user", "content": message})
|
69 |
|
@@ -80,6 +92,11 @@ def respond(
|
|
80 |
yield response
|
81 |
|
82 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
83 |
chatbot = gr.ChatInterface(
|
84 |
respond,
|
85 |
additional_inputs=[
|
@@ -93,6 +110,9 @@ with gr.Blocks() as demo:
|
|
93 |
step=0.05,
|
94 |
label="Top-p (nucleus sampling)",
|
95 |
),
|
|
|
|
|
|
|
96 |
],
|
97 |
)
|
98 |
|
|
|
6 |
# Hugging Face Inference Client
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# Function to analyze issues and provide solutions
|
10 |
def analyze_issues(issue_text, model_name):
|
11 |
nlp = pipeline("text-generation", model=model_name)
|
|
|
20 |
max_tokens,
|
21 |
temperature,
|
22 |
top_p,
|
23 |
+
github_api_token,
|
24 |
+
github_username,
|
25 |
+
github_repository
|
26 |
):
|
27 |
+
global GITHUB_API_TOKEN
|
28 |
+
GITHUB_API_TOKEN = github_api_token
|
29 |
+
|
30 |
messages = [{"role": "system", "content": system_message}]
|
31 |
|
32 |
for val in history:
|
|
|
36 |
messages.append({"role": "assistant", "content": val[1]})
|
37 |
|
38 |
if message.startswith("/github"):
|
39 |
+
if not GITHUB_API_TOKEN:
|
40 |
+
yield "Please enter your GitHub API token first. [Click here to get your token](https://github.com/settings/tokens)"
|
41 |
+
else:
|
42 |
+
try:
|
43 |
+
url = f"https://api.github.com/repos/{github_username}/{github_repository}/issues"
|
44 |
+
headers = {
|
45 |
+
"Authorization": f"Bearer {GITHUB_API_TOKEN}",
|
46 |
+
"Accept": "application/vnd.github.v3+json"
|
47 |
+
}
|
48 |
+
response = requests.get(url, headers=headers)
|
49 |
+
if response.status_code == 200:
|
50 |
+
issues = response.json()
|
51 |
+
issue_list = "\n".join([f"{i+1}. {issue['title']}" for i, issue in enumerate(issues)])
|
52 |
+
yield f"Available GitHub Issues:\n{issue_list}\n\nEnter the issue number to analyze:"
|
53 |
+
else:
|
54 |
+
yield f"Error fetching GitHub issues: {response.status_code}"
|
55 |
+
except Exception as e:
|
56 |
+
yield f"Error fetching GitHub issues: {e}"
|
57 |
elif message.isdigit():
|
58 |
+
if not GITHUB_API_TOKEN:
|
59 |
+
yield "Please enter your GitHub API token first. [Click here to get your token](https://github.com/settings/tokens)"
|
60 |
+
else:
|
61 |
+
try:
|
62 |
+
issue_number = int(message) - 1
|
63 |
+
url = f"https://api.github.com/repos/{github_username}/{github_repository}/issues"
|
64 |
+
headers = {
|
65 |
+
"Authorization": f"Bearer {GITHUB_API_TOKEN}",
|
66 |
+
"Accept": "application/vnd.github.v3+json"
|
67 |
+
}
|
68 |
+
response = requests.get(url, headers=headers)
|
69 |
+
if response.status_code == 200:
|
70 |
+
issues = response.json()
|
71 |
+
issue = issues[issue_number]
|
72 |
+
issue_text = issue['title'] + "\n\n" + issue['body']
|
73 |
+
resolution = analyze_issues(issue_text, "gpt2") # Default to gpt2 for now
|
74 |
+
yield f"Resolution for Issue '{issue['title']}':\n{resolution}"
|
75 |
+
else:
|
76 |
+
yield f"Error fetching GitHub issues: {response.status_code}"
|
77 |
+
except Exception as e:
|
78 |
+
yield f"Error analyzing issue: {e}"
|
79 |
else:
|
80 |
messages.append({"role": "user", "content": message})
|
81 |
|
|
|
92 |
yield response
|
93 |
|
94 |
with gr.Blocks() as demo:
|
95 |
+
with gr.Row():
|
96 |
+
github_api_token = gr.Textbox(label="GitHub API Token", type="password")
|
97 |
+
github_username = gr.Textbox(label="GitHub Username")
|
98 |
+
github_repository = gr.Textbox(label="GitHub Repository")
|
99 |
+
|
100 |
chatbot = gr.ChatInterface(
|
101 |
respond,
|
102 |
additional_inputs=[
|
|
|
110 |
step=0.05,
|
111 |
label="Top-p (nucleus sampling)",
|
112 |
),
|
113 |
+
github_api_token,
|
114 |
+
github_username,
|
115 |
+
github_repository
|
116 |
],
|
117 |
)
|
118 |
|