-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcaption_cpp_client.py
executable file
·61 lines (55 loc) · 2.13 KB
/
caption_cpp_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
59
60
61
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##
## Copyright 2023 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, GLib
import sys, os, requests
from interface import MainWindow
cpp_url = "http://127.0.0.1:7777/inference"
class cpWindow(MainWindow):
def transcribe(self, f, start_time, end_time):
files = {'file': (f, open(f, 'rb'))}
data = {'temperature': '0.2', 'response-format': 'json'}
try:
response = requests.post(cpp_url, files=files, data=data)
os.remove(f)
# Parse the JSON response
result = [response.json()]
text_chunk = result[0]['text'].strip()
# Show the captions
if text_chunk != "you":
print(text_chunk)
GLib.idle_add(self.show_caption, text_chunk)
self.text.append([start_time, end_time, text_chunk])
except Exception as e:
sys.stderr.write(f"Error: {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)