v2 / utils.py
deepaksj's picture
Upload utils.py
5e15a30 verified
Raw History Blame Contribute Delete
982 Bytes
import gradio as gr
def read_file_to_dic(file_path):
dic = {}
with open(file_path, 'r') as file:
for line in file:
# Skip comments and empty lines
if line.strip() and not line.startswith('//'):
key, value = line.strip().split('=', 1)
values = value.split(';')
dic[key] = values
return dic
def get_examples_dataset(values):
return gr.Dataset(samples=get_examples_arr(values))
def get_examples_arr(values):
samples = []
for value in values:
samples.append([value])
return samples
def get_images(imagePaths):
images = []
for imagePath in imagePaths:
try:
images.append(gr.Image(imagePath))
except gr.exceptions.InvalidPathError:
print(f"Image not found: {imagePath}")
return images
#test = read_file_to_dic('hints_config.txt')
#images = get_examples_arr(test["1"])
#for image in images:
# print(image)