bluenevus commited on
Commit
266767f
·
verified ·
1 Parent(s): f790f57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -60
app.py CHANGED
@@ -1,71 +1,139 @@
1
  import gradio as gr
2
- import threading
3
- import time
4
- import os
5
- from twilio.rest import Client
6
  import google.generativeai as genai
 
 
 
 
 
7
 
8
- # Constants
9
- TWILIO_SID = os.getenv('TWILIO_SID')
10
- TWILIO_TOKEN = os.getenv('TWILIO_TOKEN')
11
- GEMINI_KEY = os.getenv('GEMINI_KEY')
12
 
13
- # Initialize Twilio client
14
- twilio_client = Client(TWILIO_SID, TWILIO_TOKEN)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- # Initialize Gemini client
17
- gemini_client = genai.GenerativeModel('gemini-2.0-flash-lite')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- # Function to set Dial-in number and Passcode
20
- def set_call_info(number, passcode):
21
- global DIAL_IN_NUMBER, PASSCODE
22
- DIAL_IN_NUMBER = f"1{number}" # Add '1' for US-based numbers
23
- PASSCODE = passcode
24
- return "Call information set successfully."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- # Function for live transcription using Gemini
27
- def live_transcription():
28
- # Simulate a long call with live transcription using Gemini
29
- transcription_chunks = []
30
- for i in range(10): # Simulate 10 chunks
31
- chunk = gemini_client.generate_text(f"Transcription chunk {i}")
32
- transcription_chunks.append(chunk)
33
- time.sleep(1) # Simulate processing time
34
- return transcription_chunks
35
 
36
- # Function to stitch transcription chunks
37
- def stitch_transcription_chunks(chunks):
38
- return ' '.join(chunks)
39
-
40
- # Function to generate meeting minutes using Gemini
41
- def generate_meeting_minutes(transcript):
42
- return gemini_client.generate_text(f"Meeting minutes based on: {transcript}")
 
43
 
44
- # Function to download transcript or meeting minutes as Word document
45
- def download_as_word(text, filename):
46
- doc = Document()
47
- doc.add_paragraph(text)
48
- doc.save(filename)
49
- return filename
50
 
51
- # Gradio Interface
52
- with gr.Blocks() as demo:
53
- gr.Markdown("## Call Transcription and Meeting Minutes Generator")
54
-
55
- with gr.Row():
56
- dial_in_number = gr.Textbox(label="Dial-in Number (without '1')")
57
- passcode = gr.Textbox(label="Passcode")
58
- set_call_button = gr.Button("Set Call Information")
59
- set_call_button.click(set_call_info, inputs=[dial_in_number, passcode], outputs=gr.Textbox(label="Status"))
60
-
61
- with gr.Row():
62
- hang_up_button = gr.Button("Hang Up")
63
- hang_up_button.click(lambda: "Call ended", outputs=gr.Textbox(label="Status"))
64
-
65
- with gr.Row():
66
- transcription_output = gr.Textbox(label="Live Transcription Output")
67
- minutes_output = gr.Textbox(label="Meeting Minutes Output")
68
- download_button = gr.Button("Download Transcript and Minutes")
69
- download_button.click(lambda: download_as_word(f"{transcription_output.value}\n{minutes_output.value}", "output.docx"), outputs=gr.File(label="Download"))
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
- demo.launch(share=True)
 
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()