Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,8 +71,103 @@ def send_it1(inputs, model_choice):
|
|
| 71 |
|
| 72 |
# Gradio interface layout and logic
|
| 73 |
with gr.Blocks() as myface:
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
# Launch the Gradio interface
|
| 77 |
myface.queue(concurrency_count=200)
|
| 78 |
myface.launch(inline=True, show_api=False, max_threads=400)
|
|
|
|
| 71 |
|
| 72 |
# Gradio interface layout and logic
|
| 73 |
with gr.Blocks() as myface:
|
| 74 |
+
gr.HTML("""<!DOCTYPE html>
|
| 75 |
+
<html lang="en">
|
| 76 |
+
<head>
|
| 77 |
+
<meta charset="utf-8" />
|
| 78 |
+
<meta name="twitter:card" content="player"/>
|
| 79 |
+
<meta name="twitter:site" content=""/>
|
| 80 |
+
<meta name="twitter:player" content="https://omnibus-maximum-multiplier-places.hf.space"/>
|
| 81 |
+
<meta name="twitter:player:stream" content="https://omnibus-maximum-multiplier-places.hf.space"/>
|
| 82 |
+
<meta name="twitter:player:width" content="100%"/>
|
| 83 |
+
<meta name="twitter:player:height" content="600"/>
|
| 84 |
+
<meta property="og:title" content="Embedded Live Viewer"/>
|
| 85 |
+
<meta property="og:description" content="Tweet Genie - A Huggingface Space"/>
|
| 86 |
+
<meta property="og:image" content="https://cdn.glitch.global/80dbe92e-ce75-44af-84d5-74a2e21e9e55/omnicard.png?v=1676772531627"/>
|
| 87 |
+
<!--<meta http-equiv="refresh" content="0; url=https://huggingface.co/spaces/corbt/tweet-genie">-->
|
| 88 |
+
</head>
|
| 89 |
+
</html>
|
| 90 |
+
""")
|
| 91 |
|
| 92 |
+
with gr.Row():
|
| 93 |
+
with gr.Column(scale=100):
|
| 94 |
+
saved_output = gr.HTML(label="Saved Prompts and Images")
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Tab("Title"):
|
| 98 |
+
gr.HTML("""<title>Prompt to Generate Image</title><div style="text-align: center; max-width: 1500px; margin: 0 auto;">
|
| 99 |
+
<h1>Enter a Prompt in Textbox then click Generate Image</h1>""")
|
| 100 |
+
|
| 101 |
+
with gr.Tab("Tools"):
|
| 102 |
+
with gr.Tab("View"):
|
| 103 |
+
with gr.Row():
|
| 104 |
+
with gr.Column(style="width=50%, height=70%"):
|
| 105 |
+
gr.Pil(label="Crop")
|
| 106 |
+
with gr.Column(style="width=50%, height=70%"):
|
| 107 |
+
gr.Pil(label="Crop")
|
| 108 |
+
|
| 109 |
+
with gr.Tab("Draw"):
|
| 110 |
+
with gr.Column(style="width=50%, height=70%"):
|
| 111 |
+
gr.Pil(label="Crop")
|
| 112 |
+
with gr.Column(style="width=50%, height=70%"):
|
| 113 |
+
gr.Pil(label="Draw")
|
| 114 |
+
gr.ImagePaint(label="Draw")
|
| 115 |
+
|
| 116 |
+
with gr.Tab("Text"):
|
| 117 |
+
with gr.Row():
|
| 118 |
+
with gr.Column(scale=50):
|
| 119 |
+
gr.Textbox(label="", lines=8, interactive=True)
|
| 120 |
+
with gr.Column(scale=50):
|
| 121 |
+
gr.Textbox(label="", lines=8, interactive=True)
|
| 122 |
+
|
| 123 |
+
with gr.Tab("Color Picker"):
|
| 124 |
+
with gr.Row():
|
| 125 |
+
with gr.Column(scale=50):
|
| 126 |
+
gr.ColorPicker(label="Color", interactive=True)
|
| 127 |
+
with gr.Column(scale=50):
|
| 128 |
+
gr.ImagePaint(label="Draw", interactive=True)
|
| 129 |
+
with gr.Row():
|
| 130 |
+
with gr.Column(scale=100):
|
| 131 |
+
magic1=gr.Textbox(lines=4)
|
| 132 |
+
run=gr.Button("Generate Image")
|
| 133 |
+
|
| 134 |
+
with gr.Row():
|
| 135 |
+
with gr.Column(scale=100):
|
| 136 |
+
model_name1 = gr.Dropdown(label="Select Model", choices=[m for m in models], type="index", value=current_model, interactive=True)
|
| 137 |
+
|
| 138 |
+
with gr.Row():
|
| 139 |
+
with gr.Column(style="width=800px"):
|
| 140 |
+
output1=gr.Image(label=(f"{current_model}"))
|
| 141 |
+
# Check the type before attempting to save the image
|
| 142 |
+
if isinstance(output1, Image.Image): # Check if it's a PIL Image object
|
| 143 |
+
output1.save(image_path)
|
| 144 |
+
elif isinstance(output1, np.ndarray): # Check if it's a NumPy array
|
| 145 |
+
Image.fromarray(np.array(output1, dtype=np.uint8)).save(image_path)
|
| 146 |
+
else:
|
| 147 |
+
print(f"Warning: Unexpected type {type(output1)} for output1.")
|
| 148 |
+
|
| 149 |
+
with gr.Row():
|
| 150 |
+
with gr.Column(scale=50):
|
| 151 |
+
input_text=gr.Textbox(label="Prompt Idea",lines=2)
|
| 152 |
+
use_short=gr.Button("Use Short Prompt")
|
| 153 |
+
see_prompts=gr.Button("Extend Idea")
|
| 154 |
+
|
| 155 |
+
with gr.Row():
|
| 156 |
+
with gr.Column(scale=100):
|
| 157 |
+
saved_output = gr.HTML(label=list_saved_prompts_and_images(), live=True)
|
| 158 |
+
|
| 159 |
+
def short_prompt(inputs):
|
| 160 |
+
return(inputs)
|
| 161 |
+
|
| 162 |
+
use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
|
| 163 |
+
see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
|
| 164 |
+
|
| 165 |
+
# Reasoning: Link functions to Gradio components 🎛️
|
| 166 |
+
model_name1.change(set_model, inputs=model_name1, outputs=[output1])
|
| 167 |
+
run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1])
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
|
| 171 |
# Launch the Gradio interface
|
| 172 |
myface.queue(concurrency_count=200)
|
| 173 |
myface.launch(inline=True, show_api=False, max_threads=400)
|