Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,9 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
models = [
|
| 7 |
{"name": "Stable Diffusion 2", "url": "stabilityai/stable-diffusion-2-1"},
|
|
@@ -78,6 +81,48 @@ with gr.Blocks(css='style.css') as myface:
|
|
| 78 |
magic4 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 79 |
magic5 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 80 |
magic6 = gr.Textbox(label="Generated Prompt", lines=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6])
|
| 83 |
|
|
|
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
from pathlib import Path
|
| 5 |
+
import os
|
| 6 |
+
import numpy as np
|
| 7 |
+
from gradio import *
|
| 8 |
|
| 9 |
models = [
|
| 10 |
{"name": "Stable Diffusion 2", "url": "stabilityai/stable-diffusion-2-1"},
|
|
|
|
| 81 |
magic4 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 82 |
magic5 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 83 |
magic6 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# Set up the GUI
|
| 87 |
+
with Blocks() as demo:
|
| 88 |
+
# Create a State variable to store the selected image
|
| 89 |
+
img = State()
|
| 90 |
+
|
| 91 |
+
# Define a function to load the image from the local storage directory
|
| 92 |
+
def load_image(directory):
|
| 93 |
+
# Get the list of files in the directory
|
| 94 |
+
filenames = os.listdir(directory)
|
| 95 |
+
|
| 96 |
+
# Select the first image file (e.g. "image1.jpg")
|
| 97 |
+
filename = filenames[0]
|
| 98 |
+
|
| 99 |
+
# Load the image using numpy.load()
|
| 100 |
+
img_data = np.load(os.path.join(directory, filename))
|
| 101 |
+
|
| 102 |
+
# Convert the image data to a NumPy array
|
| 103 |
+
img = np.array(img_data)
|
| 104 |
+
return img
|
| 105 |
+
|
| 106 |
+
# Create a Gallery widget to display the loaded image
|
| 107 |
+
gallery = Gallery(directory='home/downloads/images')
|
| 108 |
+
|
| 109 |
+
# Add the image to the gallery
|
| 110 |
+
gallery.add(img)
|
| 111 |
+
|
| 112 |
+
# Create a Button widget to trigger the darkening of the image
|
| 113 |
+
darken_btn = Button("Darken Image")
|
| 114 |
+
|
| 115 |
+
# Define a function to darken the image
|
| 116 |
+
def darken_img(img):
|
| 117 |
+
# Darken the image by multiplying each pixel value by 0.8
|
| 118 |
+
darkened_img = np.round(img * 0.8).astype(np.uint8)
|
| 119 |
+
return darkened_img
|
| 120 |
+
|
| 121 |
+
# Connect the Button widget to the darken_img function
|
| 122 |
+
darken_btn.click(darken_img, [img], [gallery])
|
| 123 |
+
|
| 124 |
+
# Launch the GUI
|
| 125 |
+
demo.launch()
|
| 126 |
|
| 127 |
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6])
|
| 128 |
|