October 22, 2024
Chicago 12, Melborne City, USA
python

How do I download the image with metadata in Python?

I am downloading some images in Python from the Airtable API and am trying to make a slideshow with them using ffmpeg. I download the images: urllib2.urlretrieve(img['url'], "output/images/image_"+str(i)+".jpeg") However, when I run the following ffmpeg command ffmpeg -framerate 4/60 -i output/images/image_%d.jpeg output/out.mp4 I get the following error: ffmpeg version 6.1.1-3ubuntu5 Copyright (c) 2000-2023 the FFmpeg

Read More
python

ValueError: mismatched dimensions in reward arrays during DAgger imitation learning

I’m implementing imitation learning using the DAgger algorithm from the imitation library in Python. The environment I’m working with is a custom Gym environment that simulates a shallow lake management problem. The expert policy is generated from an optimization process, and I’m trying to train a learner policy using the DAgger framework. I’m encountering the

Read More
python

PYTHON Execute code only while Mouse right is held

Is there any way to execute python code only while Mouse button right is held? If Mouse right becomes up code should interrupt immediately. I tried to use pynput library but pressed parameter does not work on while loop. Whithout while it works right: prints correct message on Mouse right down and Mouse right up

Read More
python

Stop and resume process by semaphore

I wish to implement an API that utilize asyncio events in order to stop/resume a asyncio task. The API will support the following methods: /import (start) /stop /resume Main problem is happening when invoking the method /stop: File "/src/srv.py", line 131, in __stop loop.run_until_complete(self.__proc.stop()) RuntimeError: This event loop is already running /lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py:-1: RuntimeWarning: coroutine 'Application.stop'

Read More
python

Changing instance's attribute name via metaclass

I’m to do a metaclass that should add a prefix ‘custom_’ to all the properties and methods of my class CustomClass except for magic methods. Here is the code: class CustomClass(metaclass=CustomMeta): x = 50 def __init__(self, val=99): self.val = val def line(self): return 100 def __str__(self): return "Custom_by_metaclass" I wrote a following metaclass that works

Read More
python

SQLAlchemy and proxy_association giving use default_factory error

So I am doing some learning, and I have followed several tutorials online for Flask-SQLAlchemy and dataclasses in Python. I have my app set up as bog standard as I can get: __init__.py from flask import Flask, request, jsonify from flask_cors import CORS from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://log:pass@localhost/db" app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] =

Read More
python

I was trying to use Azure translator based on the tutorial given by MS, but still when I hit translate button I get Internal Server error

from flask import Flask, redirect, url_for, request, render_template, session import requests, os, uuid, json from dotenv import load_dotenv load_dotenv() app = Flask(__name__) @app.route('/', methods=['GET']) def index(): return render_template('index.html') @app.route('/', methods=['POST']) def index_post(): # Read the values from the form original_text = request.form['text'] target_language = request.form['language'] # Load the values from .env key = os.environ['KEY'] endpoint

Read More
python

Tkinter gui widgets resized after including matlab plot function

I am trying to use a GUI for button and plot. When I include show_graph() function inside tabss the window is resized, also widgets and text resized to smaller. import matplotlib.pyplot as plt from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from tkinter import * from tkinter import ttk import numpy as np # Function to toggle the motor

Read More
python

Not able to use spacy “/opt/en_core_web_sm-2.2.5”

I’ve been trying to use python38-spacy:42 and python38-spacy_model_en_small:1, but they are not working. Could you please help me? Here is my template yaml file: # template.yaml AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Resources: GetWordCounts: Type: AWS::Serverless::Function Properties: Handler: word-counts/app.lambda_handler Runtime: python3.8 CodeUri: . Timeout: 30 Layers: - arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-spacy:42 - arn:aws:lambda:us-east-1:770693421928:layer:Klayers-python38-spacy_model_en_small:1 Events: ApiGateway: Type: Api Properties: Path: /word-counts

Read More
python

How to check if WindowsPath is_absolute() if path is provided in posix format (ie '/windows/')

I have a CLI that is suppose to accept absolute paths but not relative paths. I set up my promp_toolkit PathCompleter to only complete absolute paths, only to be surprised that it would allow me to use posix strings to resolve windows directories. So for example if I want something in C:\Windows I can put

Read More