Python Forum
I downloaded a script and I cant run this
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I downloaded a script and I cant run this
#1
Hi, I’m a newbee to programming (and not a native speaker), recently I download a script from hugging face, and strictly follow every steps. (CiaraRowles/TemporalNet · Hugging Face)

there is a step which is to Customize the script according to my preferences, so I think the problem must be here, I probably modify some rows wrong.
everytime i try to execute the Python script, python will flash for half second and immediately shut, so i don’t even know where the error is…
here are the codes:

import os
import glob
import requests
import json
from pprint import pprint
import base64
from io import BytesIO


# Replace with the actual path to your image file and folder
x_path = "./init.png"
y_folder = "./Input_Images"

output_folder = "C:\Users\tuotuo\Desktop\yuanbao\QingShe"
os.makedirs(output_folder, exist_ok=True)

def get_image_paths(folder):
    image_extensions = ("*.jpg", "*.jpeg", "*.png", "*.bmp")
    files = []
    for ext in image_extensions:
        files.extend(glob.glob(os.path.join(folder, ext)))
    return sorted(files)

y_paths = get_image_paths(y_folder)

def send_request(last_image_path, temp_path,current_image_path):
    url = "http://localhost:7860/sdapi/v1/img2img"

    with open(last_image_path, "rb") as f:
        last_image = base64.b64encode(f.read()).decode("utf-8")

    with open(current_image_path, "rb") as b:
        current_image = base64.b64encode(b.read()).decode("utf-8")

    data = {
        "init_images": [current_image],
        "inpainting_fill": 0,
        "inpaint_full_res": True,
        "inpaint_full_res_padding": 1,
        "inpainting_mask_invert": 1,
        "resize_mode": 0,
        "denoising_strength": 0.75,
        "prompt": "1girl, (masterpiece), (high quality), lock of hair on chest, <lora:amesihls:0.4>, <lora:honglou:0.4>, <lora:Geruosi:0.2>, long sleeves, back of hand,",
        "negative_prompt": "(photography),lowres, bad anatomy, text, error, extra digit, fewer digits, cropped, worst quality,quality, normal quality, blurry, monster, wrong hand, black eyeliner,",
        "alwayson_scripts": {
            "ControlNet":{
                "args": [
                    {
                        "input_image": current_image,
                        "module": "hed",
                        "model": "amesihls [fc45b639b2]",
                        "weight": 1.5,
                        "guidance": 1,
                   },
                    {
                        "input_image": last_image,
                        "model": "diff_control_sd15_temporalnet_fp16 [adc6bd97]",
                        "module": "none",
                        "weight": 0.7,
                        "guidance": 1,
                    }
                  
                ]
            }
        },
        "seed": 4010640118,
        "subseed": -1,
        "subseed_strength": -1,
        "sampler_index": "DPM++ SDE Karras",
        "batch_size": 1,
        "n_iter": 1,
        "steps": 20,
        "cfg_scale": 7,
        "width": 1216,
        "height": 576,
        "restore_faces": True,
        "include_init_images": True,
        "override_settings": {},
        "override_settings_restore_afterwards": True
    }
    response = requests.post(url, json=data)
    if response.status_code == 200:
        return response.content
    else:
        try:
            error_data = response.json()
            print("Error:")
            print(str(error_data))
            
        except json.JSONDecodeError:
            print(f"Error: Unable to parse JSON error data.")
        return None

output_images = []
output_images.append(send_request(x_path,y_folder, y_paths[0]))
output_paths = []

for i in range(1, len(y_paths)):
     result_image = output_images[i-1]
     temp_image_path = os.path.join(output_folder, f"temp_image_{i}.png")
     data = json.loads(result_image)
     encoded_image = data["images"][0]
     with open(temp_image_path, "wb") as f:
         f.write(base64.b64decode(encoded_image))
     output_paths.append(temp_image_path)
     result = send_request(temp_image_path, y_folder, y_paths[i])
     output_images.append(result)
     print(f"Written data for frame {i}:")
Reply
#2
what is the command you are using when trying to execute the code?
Reply
#3
(Apr-15-2023, 11:24 AM)Larz60+ Wrote: what is the command you are using when trying to execute the code?

at the beginning i just double click it and it doesn't execute; then i run opened the terminal window: cd to the folder, and py to run script.
but when i enter these, the terminal shows: ‘py’ is not recognized as an internal or external command, operable program
or a batch file.

it seems that i haven't install or set something, but i don't know, i downloaded my python from python.org
[Image: 2dc13a03e127e29c8884ba9dc3f07d976b89e4b9.jpeg]
Reply
#4
First see what's installed: python3 -V
Current version is 3.11.3
If not what you expect, navigate to python.org
and install a new version.
you should use command python3 modulename.py from command line to run script.

A better way is to use an IDE (such as VSCode or pyCharm) and execute your python code from within.
see VSCode from start for example
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Downloaded file corrupted emont 5 842 Oct-01-2023, 11:32 AM
Last Post: snippsat
  How to create local copies of Python packages so they do not have to be downloaded okhajut 3 2,038 Sep-29-2020, 02:22 PM
Last Post: buran
  How to create an environment for program downloaded from github StartedNewLife 3 2,201 Jan-25-2020, 06:34 PM
Last Post: ibreeden
  Why the file is not downloaded in full with this script? Jacklops 2 2,716 Jan-07-2019, 09:33 AM
Last Post: DeaD_EyE
  importing downloaded usb module kiyoshi7 5 4,438 Apr-29-2018, 06:44 PM
Last Post: snippsat
  Can't get a downloaded file converter to work Godotisnothere 1 3,191 Jan-24-2017, 06:01 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020