Spaces:
Runtime error
Runtime error
Brian Watson
commited on
Commit
Β·
ba3d642
1
Parent(s):
e8c3fc8
Update app.py
Browse files
app.py
CHANGED
@@ -102,20 +102,130 @@ with gr.Interface(
|
|
102 |
css=css,
|
103 |
capture_session=True
|
104 |
) as iface:
|
105 |
-
model_dropdown = gr.
|
106 |
label="Choose Model",
|
107 |
choices=[m["name"] for m in models],
|
108 |
type="index",
|
109 |
value=current_model["name"],
|
110 |
interactive=True,
|
111 |
component_id="model_dropdown"
|
112 |
-
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
-
iface.inputs.insert(0, model_dropdown)
|
117 |
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
css=css,
|
103 |
capture_session=True
|
104 |
) as iface:
|
105 |
+
model_dropdown = gr.inputs.Dropdown(
|
106 |
label="Choose Model",
|
107 |
choices=[m["name"] for m in models],
|
108 |
type="index",
|
109 |
value=current_model["name"],
|
110 |
interactive=True,
|
111 |
component_id="model_dropdown"
|
112 |
+
I apologize for the incomplete code. It seems that there was an error in the last part. Here's the corrected code:
|
113 |
|
114 |
+
```python
|
115 |
+
import gradio as gr
|
116 |
+
|
117 |
+
models = [
|
118 |
+
{"name": "Claudfuen 1", "url": "claudfuen/photorealistic-fuen-v1"},
|
119 |
+
{"name": "Deliberate", "url": "Masagin/Deliberate"},
|
120 |
+
{"name": "Seek Art Mega", "url": "coreco/seek.art_MEGA"},
|
121 |
+
{"name": "Realistic Vision 1.4", "url": "SG161222/Realistic_Vision_V1.4"},
|
122 |
+
{"name": "Dreamshaper", "url": "Lykon/DreamShaper"},
|
123 |
+
]
|
124 |
+
|
125 |
+
current_model = models[0]
|
126 |
+
|
127 |
+
text_gen = gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
|
128 |
+
|
129 |
+
models2 = []
|
130 |
+
for model in models:
|
131 |
+
model_url = f"models/{model['url']}"
|
132 |
+
loaded_model = gr.Interface.load(model_url, live=True, preprocess=True)
|
133 |
+
models2.append(loaded_model)
|
134 |
+
|
135 |
+
|
136 |
+
def text_it(inputs, text_gen=text_gen):
|
137 |
+
return text_gen(inputs)
|
138 |
+
|
139 |
+
|
140 |
+
def set_model(current_model_index):
|
141 |
+
global current_model
|
142 |
+
current_model = models[current_model_index]
|
143 |
+
return gr.outputs.Label(f"Current Model: {current_model['name']}")
|
144 |
+
|
145 |
+
|
146 |
+
def send_it(inputs, model_choice):
|
147 |
+
proc = models2[model_choice]
|
148 |
+
return proc(inputs)
|
149 |
+
|
150 |
+
|
151 |
+
css = """
|
152 |
+
<style>
|
153 |
+
.searchable-dropdown {
|
154 |
+
position: relative;
|
155 |
+
}
|
156 |
+
|
157 |
+
.searchable-dropdown input {
|
158 |
+
width: 100%;
|
159 |
+
padding: 0.5rem;
|
160 |
+
border-radius: 5px;
|
161 |
+
border: 1px solid #ccc;
|
162 |
+
}
|
163 |
+
|
164 |
+
.searchable-dropdown select {
|
165 |
+
width: 100%;
|
166 |
+
padding: 0.5rem;
|
167 |
+
border-radius: 5px;
|
168 |
+
border: 1px solid #ccc;
|
169 |
+
position: absolute;
|
170 |
+
top: 0;
|
171 |
+
left: 0;
|
172 |
+
opacity: 0;
|
173 |
+
pointer-events: none;
|
174 |
+
}
|
175 |
+
</style>
|
176 |
+
"""
|
177 |
|
|
|
178 |
|
179 |
+
def make_dropdown_searchable(dropdown_id):
|
180 |
+
script = f"""
|
181 |
+
<script>
|
182 |
+
function makeDropdownSearchable(dropdownId) {{
|
183 |
+
const input = document.getElementById(dropdownId);
|
184 |
+
input.addEventListener("input", function() {{
|
185 |
+
const value = this.value.toLowerCase();
|
186 |
+
const options = Array.from(document.querySelectorAll(`#${dropdownId} option`));
|
187 |
+
let found = false;
|
188 |
+
for (let i = 0; i < options.length; i++) {{
|
189 |
+
const option = options[i];
|
190 |
+
const text = option.text.toLowerCase();
|
191 |
+
const match = text.includes(value);
|
192 |
+
option.style.display = match ? "block" : "none";
|
193 |
+
if (match) {{
|
194 |
+
found = true;
|
195 |
+
}}
|
196 |
+
}}
|
197 |
+
if (value && !found) {{
|
198 |
+
const firstOption = options[0];
|
199 |
+
if (firstOption) {{
|
200 |
+
firstOption.selected = true;
|
201 |
+
}}
|
202 |
+
}}
|
203 |
+
}});
|
204 |
+
}}
|
205 |
+
|
206 |
+
makeDropdownSearchable("{dropdown_id}");
|
207 |
+
</script>
|
208 |
+
"""
|
209 |
+
return gr.outputs.HTML(script)
|
210 |
|
211 |
+
|
212 |
+
iface = gr.Interface(
|
213 |
+
fn=text_it,
|
214 |
+
inputs="text",
|
215 |
+
outputs="text",
|
216 |
+
css=css,
|
217 |
+
capture_session=True
|
218 |
+
)
|
219 |
+
|
220 |
+
model_dropdown = gr.inputs.Dropdown(
|
221 |
+
label="Choose Model",
|
222 |
+
choices=[m["name"] for m in models],
|
223 |
+
type="index",
|
224 |
+
value=current_model["name"],
|
225 |
+
interactive=True,
|
226 |
+
description="Select the model to use for text generation"
|
227 |
+
)
|
228 |
+
|
229 |
+
iface.add_input(model_dropdown, set_model)
|
230 |
+
iface.add_input("text", send_it, "output")
|
231 |
+
iface.launch()
|