Update app.py
Browse files
app.py
CHANGED
@@ -1,142 +1,71 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
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 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
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 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
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 |
-
|
66 |
-
|
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 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
elif line:
|
95 |
-
markdown_content += f"- {line}\n"
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
return release_notes, docx_path, md_path
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
)
|
116 |
-
gr.
|
117 |
-
|
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 |
-
|
|
|
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)
|