bluenevus commited on
Commit
d36ddc9
·
verified ·
1 Parent(s): 669441a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from datetime import datetime, timedelta
3
  import google.generativeai as genai
4
  from github import Github, GithubException
 
5
 
6
  def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
7
  try:
@@ -21,7 +22,7 @@ def generate_release_notes(github_url, github_token, gemini_api_key, start_date,
21
  commit_text = "\n".join(commit_messages)
22
 
23
  if not commit_text:
24
- return "No commits found in the specified date range."
25
 
26
  # Use Gemini AI to generate release notes
27
  genai.configure(api_key=gemini_api_key)
@@ -41,21 +42,30 @@ def generate_release_notes(github_url, github_token, gemini_api_key, start_date,
41
 
42
  response = model.generate_content(prompt)
43
 
44
- return response.text
 
 
 
 
 
 
 
 
 
45
 
46
  except GithubException as e:
47
  if e.status == 401:
48
- return "Error: Invalid GitHub token or insufficient permissions."
49
  elif e.status == 404:
50
- return f"Error: Repository not found. Please check the GitHub URL. Attempted to access: {github_url}"
51
  else:
52
- return f"GitHub API error: {str(e)}"
53
  except Exception as e:
54
- return f"An error occurred: {str(e)}"
55
 
56
  # Set default dates
57
  default_end_date = datetime.now()
58
- default_start_date = default_end_date - timedelta(days=7) # One week ago
59
 
60
  # Create Gradio interface
61
  iface = gr.Interface(
@@ -75,7 +85,10 @@ iface = gr.Interface(
75
  value=default_end_date.strftime("%Y-%m-%d"),
76
  )
77
  ],
78
- outputs=gr.Textbox(label="Generated Release Notes"),
 
 
 
79
  title="Automated Release Notes Generator",
80
  description="Generate release notes based on GitHub commits using Gemini AI. Enter start and end dates (YYYY-MM-DD) to define the time range for commits.",
81
  allow_flagging="never",
 
2
  from datetime import datetime, timedelta
3
  import google.generativeai as genai
4
  from github import Github, GithubException
5
+ import docx
6
 
7
  def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
8
  try:
 
22
  commit_text = "\n".join(commit_messages)
23
 
24
  if not commit_text:
25
+ return "No commits found in the specified date range.", None
26
 
27
  # Use Gemini AI to generate release notes
28
  genai.configure(api_key=gemini_api_key)
 
42
 
43
  response = model.generate_content(prompt)
44
 
45
+ # Create a Word document
46
+ doc = docx.Document()
47
+ doc.add_heading('Release Notes', 0)
48
+ doc.add_paragraph(response.text)
49
+
50
+ # Save the document to a temporary file
51
+ temp_file = "release_notes.docx"
52
+ doc.save(temp_file)
53
+
54
+ return response.text, temp_file
55
 
56
  except GithubException as e:
57
  if e.status == 401:
58
+ return "Error: Invalid GitHub token or insufficient permissions.", None
59
  elif e.status == 404:
60
+ return f"Error: Repository not found. Please check the GitHub URL. Attempted to access: {github_url}", None
61
  else:
62
+ return f"GitHub API error: {str(e)}", None
63
  except Exception as e:
64
+ return f"An error occurred: {str(e)}", None
65
 
66
  # Set default dates
67
  default_end_date = datetime.now()
68
+ default_start_date = default_end_date - timedelta(days=30) # One month ago
69
 
70
  # Create Gradio interface
71
  iface = gr.Interface(
 
85
  value=default_end_date.strftime("%Y-%m-%d"),
86
  )
87
  ],
88
+ outputs=[
89
+ gr.Textbox(label="Generated Release Notes"),
90
+ gr.File(label="Download Release Notes")
91
+ ],
92
  title="Automated Release Notes Generator",
93
  description="Generate release notes based on GitHub commits using Gemini AI. Enter start and end dates (YYYY-MM-DD) to define the time range for commits.",
94
  allow_flagging="never",