feat: added model selector

This commit is contained in:
Yandrik 2024-05-02 08:46:09 +02:00
parent 95f22c268b
commit a264e91f1f
2 changed files with 44 additions and 3 deletions

View File

@ -109,6 +109,7 @@ def _gen_text(prompt, use_zukijourney=False):
@app.route('/gen_image', methods=['GET']) @app.route('/gen_image', methods=['GET'])
def gen_image(): def gen_image():
prompt = request.args.get('prompt') prompt = request.args.get('prompt')
model = request.args.get('model', 'playground-v2.5')
if not prompt: if not prompt:
return "Error: No prompt provided", 400 return "Error: No prompt provided", 400
@ -119,7 +120,7 @@ def gen_image():
try: try:
client = get_client() client = get_client()
response = client.images.generate( response = client.images.generate(
model="playground-v2.5", model=model,
prompt=prompt, prompt=prompt,
) )
image_url = response.data[0].url image_url = response.data[0].url

View File

@ -1,9 +1,38 @@
<script lang="ts"> <script lang="ts">
import { ProgressRadial, getToastStore } from '@skeletonlabs/skeleton'; import { ProgressRadial, getToastStore, RadioGroup, RadioItem } from '@skeletonlabs/skeleton';
let inputText = ''; let inputText = '';
let imageUrl = ''; let imageUrl = '';
const models = [
{
name: "Runway v2.5",
value: "runway-v2.5",
},
{
name: "Dall-e 3",
value: "dall-e-3",
},
{
name: "Stable Diffusion 3",
value: "stable-diffusion-3",
},
{
name: "Pollinations",
value: "pollinations"
},
{
name: "RealVis XL 4",
value: "realvisxl-v4",
},
{
name: "CyberRealistic",
value: "cyberrealistic-v3.3",
}
]
let currentModel = models[0].value;
let generateFutureAbortController = new AbortController(); let generateFutureAbortController = new AbortController();
let generateFutureAbortSignal = generateFutureAbortController.signal; let generateFutureAbortSignal = generateFutureAbortController.signal;
@ -33,7 +62,8 @@
isGenerating = true; isGenerating = true;
try { try {
const response = await fetch( const response = await fetch(
`/api/forward/gen_image?prompt=${encodeURIComponent(inputText)}`, `/api/forward/gen_image?prompt=${encodeURIComponent(inputText)}&model=${encodeURIComponent(currentModel)}`,
{ signal } { signal }
); );
if (response.ok) { if (response.ok) {
@ -150,6 +180,16 @@
</div> </div>
{/await} {/await}
</div> </div>
<div class="px-4 mb-4">
<p>Bildgenerations-Model</p>
<RadioGroup active="variant-filled-primary" hover="hover:variant-soft-primary">
{#each models as model}
<RadioItem bind:group={currentModel} value={model.value}>
{model.name}
</RadioItem>
{/each}
</RadioGroup>
</div>
</center> </center>
<form on:submit|preventDefault={handleSubmit} class="flex flex-col md:flex-row space-x-4"> <form on:submit|preventDefault={handleSubmit} class="flex flex-col md:flex-row space-x-4">