bluenevus's picture
Update app.py
bfaeb10 verified
raw
history blame
2.21 kB
# app.py
import gradio as gr
from datetime import datetime, timedelta
import requests
def get_subdirectories(url):
response = requests.get(url)
links = response.text.split('<a href="')
subdirectories = [link.split('"')[0] for link in links if link.startswith('/docs/gradio/')]
return subdirectories
def generate_release_notes(github_url, github_token, gemini_api_key, start_date, end_date):
# Convert start_date and end_date to datetime objects if they're not already
if isinstance(start_date, str):
start_date = datetime.fromisoformat(start_date).date()
elif isinstance(start_date, datetime):
start_date = start_date.date()
if isinstance(end_date, str):
end_date = datetime.fromisoformat(end_date).date()
elif isinstance(end_date, datetime):
end_date = end_date.date()
# Get subdirectories
base_url = "https://www.gradio.app"
subdirectories = get_subdirectories(base_url + "/docs/gradio/")
full_urls = [base_url + subdir for subdir in subdirectories]
# Your existing function implementation here
# ...
return f"Generated release notes for {github_url} from {start_date} to {end_date}\n\nSubdirectories:\n" + "\n".join(full_urls)
# 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.Date(
label="Start Date",
value=default_start_date.date(),
),
gr.Date(
label="End Date",
value=default_end_date.date(),
)
],
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()