Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,139 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import time
|
4 |
-
import os
|
5 |
-
from twilio.rest import Client
|
6 |
import google.generativeai as genai
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
return transcription_chunks
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
doc = Document()
|
47 |
-
doc.add_paragraph(text)
|
48 |
-
doc.save(filename)
|
49 |
-
return filename
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
71 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
from datetime import datetime, timedelta
|
|
|
|
|
|
|
3 |
import google.generativeai as genai
|
4 |
+
from github import Github, GithubException
|
5 |
+
import gitlab
|
6 |
+
import docx
|
7 |
+
import tempfile
|
8 |
+
import requests
|
9 |
|
10 |
+
def generate_release_notes(git_provider, repo_url, personal_access_token, gemini_api_key, start_date, end_date):
|
11 |
+
try:
|
12 |
+
start_date = datetime.strptime(start_date, "%Y-%m-%d")
|
13 |
+
end_date = datetime.strptime(end_date, "%Y-%m-%d")
|
14 |
|
15 |
+
if git_provider == "GitHub":
|
16 |
+
g = Github(personal_access_token)
|
17 |
+
repo = g.get_repo(repo_url)
|
18 |
+
commits = list(repo.get_commits(since=start_date, until=end_date))
|
19 |
+
commit_messages = [commit.commit.message for commit in commits]
|
20 |
+
elif git_provider == "GitLab":
|
21 |
+
gl = gitlab.Gitlab(url='https://gitlab.com', private_token=personal_access_token)
|
22 |
+
project = gl.projects.get(repo_url)
|
23 |
+
commits = project.commits.list(since=start_date.isoformat(), until=end_date.isoformat())
|
24 |
+
commit_messages = [commit.message for commit in commits]
|
25 |
+
elif git_provider == "Gitea":
|
26 |
+
base_url = "https://gitea.com/api/v1"
|
27 |
+
headers = {"Authorization": f"token {personal_access_token}"}
|
28 |
+
response = requests.get(f"{base_url}/repos/{repo_url}/commits", headers=headers, params={
|
29 |
+
"since": start_date.isoformat(),
|
30 |
+
"until": end_date.isoformat()
|
31 |
+
})
|
32 |
+
response.raise_for_status()
|
33 |
+
commits = response.json()
|
34 |
+
commit_messages = [commit['commit']['message'] for commit in commits]
|
35 |
+
else:
|
36 |
+
return "Unsupported Git provider", None, None
|
37 |
|
38 |
+
commit_text = "\n".join(commit_messages)
|
39 |
+
|
40 |
+
if not commit_text:
|
41 |
+
return "No commits found in the specified date range.", None, None
|
42 |
+
|
43 |
+
genai.configure(api_key=gemini_api_key)
|
44 |
+
model = genai.GenerativeModel('gemini-2.0-flash-lite')
|
45 |
+
|
46 |
+
prompt = f"""Based on the following commit messages, generate comprehensive release notes:
|
47 |
+
{commit_text}
|
48 |
+
Please organize the release notes into sections such as:
|
49 |
+
1. New Features
|
50 |
+
2. Bug Fixes
|
51 |
+
3. Improvements
|
52 |
+
4. Breaking Changes (if any)
|
53 |
+
Provide a concise summary for each item. Do not include any links, but keep issue numbers if present.
|
54 |
+
|
55 |
+
Important formatting instructions:
|
56 |
+
- The output should be plain text without any markdown or "-" for post processing
|
57 |
+
- Use section titles followed by a colon (e.g., "New Features:")
|
58 |
+
- Start each item on a new line
|
59 |
+
- Be sure to briefly explain the why and benefits of the change for average users that are non-technical
|
60 |
+
"""
|
61 |
|
62 |
+
response = model.generate_content(prompt)
|
63 |
+
release_notes = response.text
|
64 |
+
|
65 |
+
# Create DOCX file
|
66 |
+
doc = docx.Document()
|
67 |
+
doc.add_heading('Release Notes', 0)
|
68 |
+
|
69 |
+
current_section = None
|
70 |
+
for line in release_notes.split('\n'):
|
71 |
+
line = line.strip()
|
72 |
+
if line.endswith(':'):
|
73 |
+
doc.add_heading(line, level=1)
|
74 |
+
current_section = None
|
75 |
+
elif line:
|
76 |
+
if current_section is None:
|
77 |
+
current_section = doc.add_paragraph().style
|
78 |
+
current_section.name = 'List Bullet'
|
79 |
+
doc.add_paragraph(line, style=current_section)
|
80 |
+
|
81 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.docx') as temp_docx:
|
82 |
+
doc.save(temp_docx.name)
|
83 |
+
docx_path = temp_docx.name
|
84 |
|
85 |
+
# Create Markdown file
|
86 |
+
markdown_content = "# Release Notes\n\n"
|
87 |
+
for line in release_notes.split('\n'):
|
88 |
+
line = line.strip()
|
89 |
+
if line.endswith(':'):
|
90 |
+
markdown_content += f"\n## {line}\n\n"
|
91 |
+
elif line:
|
92 |
+
markdown_content += f"- {line}\n"
|
|
|
93 |
|
94 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.md', mode='w', encoding='utf-8') as temp_md:
|
95 |
+
temp_md.write(markdown_content)
|
96 |
+
md_path = temp_md.name
|
97 |
+
|
98 |
+
return release_notes, docx_path, md_path
|
99 |
+
|
100 |
+
except Exception as e:
|
101 |
+
return f"An error occurred: {str(e)}", None, None
|
102 |
|
103 |
+
default_end_date = datetime.now()
|
104 |
+
default_start_date = default_end_date - timedelta(days=30)
|
|
|
|
|
|
|
|
|
105 |
|
106 |
+
iface = gr.Interface(
|
107 |
+
fn=generate_release_notes,
|
108 |
+
inputs=[
|
109 |
+
gr.Dropdown(
|
110 |
+
choices=["GitHub", "GitLab", "Gitea"],
|
111 |
+
label="Git Provider"
|
112 |
+
),
|
113 |
+
gr.Textbox(label="Repository URL", placeholder="owner/repo"),
|
114 |
+
gr.Textbox(label="Personal Access Token", type="password"),
|
115 |
+
gr.Textbox(label="Gemini API Key", type="password"),
|
116 |
+
gr.Textbox(
|
117 |
+
label="Start Date",
|
118 |
+
placeholder="YYYY-MM-DD",
|
119 |
+
value=default_start_date.strftime("%Y-%m-%d"),
|
120 |
+
),
|
121 |
+
gr.Textbox(
|
122 |
+
label="End Date",
|
123 |
+
placeholder="YYYY-MM-DD",
|
124 |
+
value=default_end_date.strftime("%Y-%m-%d"),
|
125 |
+
)
|
126 |
+
],
|
127 |
+
outputs=[
|
128 |
+
gr.Textbox(label="Generated Release Notes"),
|
129 |
+
gr.File(label="Download Release Notes (DOCX)"),
|
130 |
+
gr.File(label="Download Release Notes (Markdown)")
|
131 |
+
],
|
132 |
+
title="Automated Release Notes Generator",
|
133 |
+
description="Generate release notes based on Git commits using Gemini AI. Select a Git provider, enter repository details, and specify the date range for commits.",
|
134 |
+
allow_flagging="never",
|
135 |
+
theme="default",
|
136 |
+
analytics_enabled=False,
|
137 |
+
)
|
138 |
|
139 |
+
iface.launch()
|