Logging to file / about dialog, youtube transcripts are downloaded on the right folder, fixed Ollama not running sometimes
This commit is contained in:
parent
7c26956cd4
commit
c0f8825f83
@ -285,9 +285,9 @@ def youtube_caption_response(self, dialog, task, video_url, caption_drop_down):
|
|||||||
selected_caption = caption_drop_down.get_selected_item().get_string()
|
selected_caption = caption_drop_down.get_selected_item().get_string()
|
||||||
for event in yt.captions[selected_caption.split(' | ')[1]].json_captions['events']:
|
for event in yt.captions[selected_caption.split(' | ')[1]].json_captions['events']:
|
||||||
text += "{}\n".format(event['segs'][0]['utf8'].replace('\n', '\\n'))
|
text += "{}\n".format(event['segs'][0]['utf8'].replace('\n', '\\n'))
|
||||||
if not os.path.exists('/tmp/alpaca/youtube'):
|
if not os.path.exists(os.path.join(self.cache_dir, 'tmp/youtube')):
|
||||||
os.makedirs('/tmp/alpaca/youtube')
|
os.makedirs(os.path.join(self.cache_dir, 'tmp/youtube'))
|
||||||
file_path = os.path.join('/tmp/alpaca/youtube', f'{yt.title} ({selected_caption.split(" | ")[0]})')
|
file_path = os.path.join(os.path.join(self.cache_dir, 'tmp/youtube'), f'{yt.title} ({selected_caption.split(" | ")[0]})')
|
||||||
with open(file_path, 'w+') as f:
|
with open(file_path, 'w+') as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
self.attach_file(file_path, 'youtube')
|
self.attach_file(file_path, 'youtube')
|
||||||
|
@ -12,10 +12,13 @@ data_dir = os.getenv("XDG_DATA_HOME")
|
|||||||
overrides = {}
|
overrides = {}
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
|
if not os.path.isdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp/ollama')):
|
||||||
|
os.mkdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp/ollama'))
|
||||||
global instance, overrides
|
global instance, overrides
|
||||||
params = overrides.copy()
|
params = overrides.copy()
|
||||||
params["OLLAMA_HOST"] = f"127.0.0.1:{port}" # You can't change this directly sorry :3
|
params["OLLAMA_HOST"] = f"127.0.0.1:{port}" # You can't change this directly sorry :3
|
||||||
params["HOME"] = data_dir
|
params["HOME"] = data_dir
|
||||||
|
params["TMPDIR"] = os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp/ollama')
|
||||||
instance = subprocess.Popen(["/app/bin/ollama", "serve"], env={**os.environ, **params}, stderr=subprocess.PIPE, text=True)
|
instance = subprocess.Popen(["/app/bin/ollama", "serve"], env={**os.environ, **params}, stderr=subprocess.PIPE, text=True)
|
||||||
logger.info("Starting Alpaca's Ollama instance...")
|
logger.info("Starting Alpaca's Ollama instance...")
|
||||||
logger.debug(params)
|
logger.debug(params)
|
||||||
|
13
src/main.py
13
src/main.py
@ -20,6 +20,7 @@
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import gi
|
import gi
|
||||||
|
import os
|
||||||
|
|
||||||
gi.require_version('Gtk', '4.0')
|
gi.require_version('Gtk', '4.0')
|
||||||
gi.require_version('Adw', '1')
|
gi.require_version('Adw', '1')
|
||||||
@ -61,7 +62,8 @@ class AlpacaApplication(Adw.Application):
|
|||||||
copyright='© 2024 Jeffser\n© 2024 Ollama',
|
copyright='© 2024 Jeffser\n© 2024 Ollama',
|
||||||
issue_url='https://github.com/Jeffser/Alpaca/issues',
|
issue_url='https://github.com/Jeffser/Alpaca/issues',
|
||||||
license_type=3,
|
license_type=3,
|
||||||
website="https://jeffser.com/alpaca")
|
website="https://jeffser.com/alpaca",
|
||||||
|
debug_info=open(os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log'), 'r').read())
|
||||||
about.present(parent=self.props.active_window)
|
about.present(parent=self.props.active_window)
|
||||||
|
|
||||||
def create_action(self, name, callback, shortcuts=None):
|
def create_action(self, name, callback, shortcuts=None):
|
||||||
@ -73,9 +75,16 @@ class AlpacaApplication(Adw.Application):
|
|||||||
|
|
||||||
|
|
||||||
def main(version):
|
def main(version):
|
||||||
|
if os.path.isfile(os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log')):
|
||||||
|
os.remove(os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log'))
|
||||||
|
if os.path.isdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp')):
|
||||||
|
os.system('rm -rf ' + os.path.join(os.getenv("XDG_CACHE_HOME"), "tmp/*"))
|
||||||
|
else:
|
||||||
|
os.mkdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp'))
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format="%(levelname)s\t[%(filename)s | %(funcName)s] %(message)s",
|
format="%(levelname)s\t[%(filename)s | %(funcName)s] %(message)s",
|
||||||
level=logging.INFO
|
level=logging.INFO,
|
||||||
|
handlers=[logging.FileHandler(filename=os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log')), logging.StreamHandler(stream=sys.stdout)]
|
||||||
)
|
)
|
||||||
app = AlpacaApplication(version)
|
app = AlpacaApplication(version)
|
||||||
logger.info(f"Alpaca version: {app.version}")
|
logger.info(f"Alpaca version: {app.version}")
|
||||||
|
@ -575,7 +575,6 @@ Generate a title following these rules:
|
|||||||
current_model = current_model.replace(' (', ':').replace(' ', '-')[:-1].lower()
|
current_model = current_model.replace(' (', ':').replace(' ', '-')[:-1].lower()
|
||||||
data = {"model": current_model, "prompt": prompt, "stream": False}
|
data = {"model": current_model, "prompt": prompt, "stream": False}
|
||||||
if 'images' in message: data["images"] = message['images']
|
if 'images' in message: data["images"] = message['images']
|
||||||
print(current_model)
|
|
||||||
response = connection_handler.simple_post(f"{connection_handler.url}/api/generate", data=json.dumps(data))
|
response = connection_handler.simple_post(f"{connection_handler.url}/api/generate", data=json.dumps(data))
|
||||||
|
|
||||||
new_chat_name = json.loads(response.text)["response"].strip().removeprefix("Title: ").removeprefix("title: ").strip('\'"').title()
|
new_chat_name = json.loads(response.text)["response"].strip().removeprefix("Title: ").removeprefix("title: ").strip('\'"').title()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user