-
Notifications
You must be signed in to change notification settings - Fork 2
/
caption_client.py
executable file
·58 lines (53 loc) · 1.95 KB
/
caption_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
## Copyright 2024 Henry Kroll <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
## MA 02110-1301, USA.
##
## Gtk includes
import gi
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
from gi.repository import Adw
import sys, os
from interface import MainWindow
from gradio_client import Client
client = Client("http://localhost:7860/")
task = "transcribe"
class cpWindow(MainWindow):
def transcribe(self, f, start_time, end_time):
try:
result = client.predict(f, task, False, api_name="/predict_1")
text_chunk = result[0].strip()
os.remove(f)
# Show the captions
if text_chunk != "you":
print(text_chunk)
self.show_caption(text_chunk)
self.text.append([start_time, end_time, text_chunk])
except Exception as e:
print("Exception:", e)
class MyApp(Adw.Application):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.connect('activate', self.on_activate)
def on_activate(self, app):
self.win = cpWindow(application=app)
self.win.present()
self.win.captions_box.set_text("Ready to transcribe.")
app = MyApp(application_id="com.comptune.rec")
app.run(sys.argv)