Spaces:
Sleeping
Sleeping
| import yaml | |
| #import pyperclip | |
| import gradio as gr | |
| #pyperclip.set_clipboard("windows") | |
| def get_options(file_path): | |
| with open(file_path, 'r') as file: | |
| options = yaml.load(file, Loader=yaml.FullLoader) | |
| return options | |
| def generate_output(topic, options): | |
| output = topic + ', ' + ', '.join([options[key] for key in options]) | |
| return output | |
| def run_app(file_path='options.yaml'): | |
| options = get_options(file_path) | |
| inputs = [ | |
| gr.inputs.Textbox(label="Enter image topic:") | |
| ] | |
| for key in options.keys(): | |
| inputs.append(gr.inputs.Dropdown(options[key], label=key)) | |
| outputs = gr.outputs.Textbox(label="Output:") | |
| def submit_handler(*input_values): | |
| topic = input_values[0] | |
| option_values = {} | |
| for i, key in enumerate(options.keys()): | |
| option_values[key] = input_values[i+1] | |
| output = generate_output(topic, option_values) | |
| # pyperclip.copy(output) | |
| return output | |
| interface = gr.Interface( | |
| submit_handler, | |
| inputs, | |
| outputs, | |
| title="Image Prompt Generator", | |
| description="Select options to generate image prompt and copy to clipboard." | |
| ) | |
| interface.launch() | |
| if __name__ == '__main__': | |
| run_app() | |