import gradio as gr import os from github import Github from datetime import datetime, timedelta import google.generativeai as genai def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date): # Configure Gemini API genai.configure(api_key=gemini_api_key) model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25') # Initialize GitHub client g = Github(github_token) # Extract repository name from URL repo_name = github_url.split('/')[-1].replace('.git', '') repo = g.get_repo(f"MicroHealthLLC/{repo_name}") # Fetch commits commits = repo.get_commits(since=start_date, until=end_date) # Prepare commit messages for AI analysis commit_messages = [commit.commit.message for commit in commits] commit_text = "\n".join(commit_messages) # Generate release notes using Gemini prompt = f"Based on the following commit messages, generate comprehensive release notes:\n\n{commit_text}\n\nPlease categorize changes, summarize features, and identify key updates." response = model.generate_content(prompt) return response.text # Set default dates default_end_date = datetime.now() default_start_date = default_end_date - timedelta(days=7) # One week ago # Create Gradio interface iface = gr.Interface( fn=generate_release_notes, inputs=[ gr.Textbox(label="GitHub Repository URL (e.g., https://github.com/MicroHealthLLC/maiko-assistant.git)"), gr.Textbox(label="GitHub Personal Access Token", type="password"), gr.Textbox(label="Gemini API Key", type="password"), gr.DateTime( label="Start Date", value=default_start_date.isoformat(), type="datetime", include_time=True ), gr.DateTime( label="End Date", value=default_end_date.isoformat(), type="datetime", include_time=True ) ], outputs=gr.Textbox(label="Generated Release Notes"), title="Automated Release Notes Generator", description="Generate release notes based on GitHub commits using Gemini AI. Select start and end dates to define the time range for commits." ) # Launch the app iface.launch()