bluenevus's picture
Update app.py
57e6cf7 verified
raw
history blame
2.74 kB
import gradio as gr
from datetime import datetime, timedelta
import requests
import google.generativeai as genai
from github import Github
def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
try:
# Initialize GitHub client
g = Github(github_token)
# Extract owner and repo from the URL
_, _, _, owner, repo = github_url.rstrip('/').split('/')
# Get the repository
repo = g.get_repo(f"{owner}/{repo}")
# Get commits between start_date and end_date
commits = repo.get_commits(since=datetime.strptime(start_date, "%Y-%m-%d"),
until=datetime.strptime(end_date, "%Y-%m-%d"))
# Prepare commit messages
commit_messages = [commit.commit.message for commit in commits]
commit_text = "\n".join(commit_messages)
# Use Gemini AI to generate release notes
genai.configure(api_key=gemini_api_key)
model = genai.GenerativeModel('gemini-pro')
prompt = f"""Based on the following commit messages, generate comprehensive release notes:
{commit_text}
Please organize the release notes into sections such as:
1. New Features
2. Bug Fixes
3. Improvements
4. Breaking Changes (if any)
Provide a concise summary for each item."""
response = model.generate_content(prompt)
return response.text
except Exception as e:
return f"An error occurred: {str(e)}"
# Set default dates
default_end_date = datetime.now()
default_start_date = default_end_date - timedelta(days=30) # One week ago
# Create Gradio interface
iface = gr.Interface(
fn=generate_release_notes,
inputs=[
gr.Textbox(label="GitHub Repository URL", placeholder="https://github.com/username/repo"),
gr.Textbox(label="GitHub Personal Access Token", type="password"),
gr.Textbox(label="Gemini API Key", type="password"),
gr.Textbox(
label="Start Date",
placeholder="YYYY-MM-DD",
value=default_start_date.strftime("%Y-%m-%d"),
),
gr.Textbox(
label="End Date",
placeholder="YYYY-MM-DD",
value=default_end_date.strftime("%Y-%m-%d"),
)
],
outputs=gr.Textbox(label="Generated Release Notes"),
title="Automated Release Notes Generator",
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.",
allow_flagging="never",
theme="default",
analytics_enabled=False,
)
# Launch the app
iface.launch()