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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -129
app.py CHANGED
@@ -1,142 +1,71 @@
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
 
48
- {commit_text}
 
 
 
 
 
49
 
50
- Please organize the release notes into sections such as:
51
- 1. New Features
52
- 2. Bug Fixes
53
- 3. Improvements
54
- 4. Breaking Changes (if any)
 
 
 
 
55
 
56
- Provide a concise summary for each item. Do not include any links, but keep issue numbers if present.
57
-
58
- Important formatting instructions:
59
- - The output should be plain text without any markdown or "-" for post processing
60
- - Use section titles followed by a colon (e.g., "New Features:")
61
- - Start each item on a new line
62
- - Be sure to briefly explain the why and benefits of the change for average users that are non-technical
63
- """
64
 
65
- response = model.generate_content(prompt)
66
- release_notes = response.text
67
-
68
- # Create DOCX file
69
- doc = docx.Document()
70
- doc.add_heading('Release Notes', 0)
71
-
72
- current_section = None
73
- for line in release_notes.split('\n'):
74
- line = line.strip()
75
- if line.endswith(':'):
76
- doc.add_heading(line, level=1)
77
- current_section = None
78
- elif line:
79
- if current_section is None:
80
- current_section = doc.add_paragraph().style
81
- current_section.name = 'List Bullet'
82
- doc.add_paragraph(line, style=current_section)
83
-
84
- with tempfile.NamedTemporaryFile(delete=False, suffix='.docx') as temp_docx:
85
- doc.save(temp_docx.name)
86
- docx_path = temp_docx.name
87
 
88
- # Create Markdown file
89
- markdown_content = "# Release Notes\n\n"
90
- for line in release_notes.split('\n'):
91
- line = line.strip()
92
- if line.endswith(':'):
93
- markdown_content += f"\n## {line}\n\n"
94
- elif line:
95
- markdown_content += f"- {line}\n"
96
 
97
- with tempfile.NamedTemporaryFile(delete=False, suffix='.md', mode='w', encoding='utf-8') as temp_md:
98
- temp_md.write(markdown_content)
99
- md_path = temp_md.name
100
-
101
- return release_notes, docx_path, md_path
102
 
103
- except Exception as e:
104
- return f"An error occurred: {str(e)}", None, None
105
-
106
- default_end_date = datetime.now()
107
- default_start_date = default_end_date - timedelta(days=30)
108
-
109
- iface = gr.Interface(
110
- fn=generate_release_notes,
111
- inputs=[
112
- gr.Dropdown(
113
- choices=["GitHub", "GitLab", "Gitea"],
114
- label="Git Provider"
115
- ),
116
- gr.Textbox(label="Repository URL", placeholder="owner/repo"),
117
- gr.Textbox(label="Personal Access Token", type="password"),
118
- gr.Textbox(label="Gemini API Key", type="password"),
119
- gr.Textbox(
120
- label="Start Date",
121
- placeholder="YYYY-MM-DD",
122
- value=default_start_date.strftime("%Y-%m-%d"),
123
- ),
124
- gr.Textbox(
125
- label="End Date",
126
- placeholder="YYYY-MM-DD",
127
- value=default_end_date.strftime("%Y-%m-%d"),
128
- )
129
- ],
130
- outputs=[
131
- gr.Textbox(label="Generated Release Notes"),
132
- gr.File(label="Download Release Notes (DOCX)"),
133
- gr.File(label="Download Release Notes (Markdown)")
134
- ],
135
- title="Automated Release Notes Generator",
136
- 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.",
137
- allow_flagging="never",
138
- theme="default",
139
- analytics_enabled=False,
140
- )
141
 
142
- iface.launch()
 
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)