Spaces:
Runtime error
Runtime error
shweaung commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,34 +5,15 @@ import io
|
|
| 5 |
import os
|
| 6 |
from fal_client import submit
|
| 7 |
|
| 8 |
-
# Google Translate Free API
|
| 9 |
-
def translate_prompt(prompt, target_lang="en"):
|
| 10 |
-
url = f"https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={target_lang}&dt=t&q={prompt}"
|
| 11 |
-
|
| 12 |
-
try:
|
| 13 |
-
response = requests.get(url)
|
| 14 |
-
if response.status_code == 200:
|
| 15 |
-
translation = response.json()[0][0][0]
|
| 16 |
-
return translation
|
| 17 |
-
else:
|
| 18 |
-
return prompt # Return original prompt in case of an error
|
| 19 |
-
except Exception as e:
|
| 20 |
-
return prompt # Return original prompt if translation fails
|
| 21 |
-
|
| 22 |
-
# Set the FAL API key
|
| 23 |
def set_fal_key(api_key):
|
| 24 |
os.environ["FAL_KEY"] = api_key
|
| 25 |
return "FAL API key set successfully!"
|
| 26 |
|
| 27 |
-
# Image Generation Function
|
| 28 |
def generate_image(api_key, model, prompt, image_size, num_inference_steps, guidance_scale, num_images, safety_tolerance, enable_safety_checker, seed):
|
| 29 |
set_fal_key(api_key)
|
| 30 |
-
|
| 31 |
-
# Translate prompt to English
|
| 32 |
-
translated_prompt = translate_prompt(prompt, target_lang="en")
|
| 33 |
|
| 34 |
arguments = {
|
| 35 |
-
"prompt":
|
| 36 |
"image_size": image_size,
|
| 37 |
"num_inference_steps": num_inference_steps,
|
| 38 |
"num_images": num_images,
|
|
@@ -91,7 +72,7 @@ def update_visible_components(model):
|
|
| 91 |
|
| 92 |
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
| 93 |
gr.HTML("""
|
| 94 |
-
<h1 align="center">FLUX.1 Image Generation
|
| 95 |
<p align="center">
|
| 96 |
<a href="https://blackforestlabs.ai/" target="_blank">[Black Forest Labs]</a>
|
| 97 |
<a href="https://blackforestlabs.ai/announcing-black-forest-labs/" target="_blank">[Blog]</a>
|
|
@@ -108,7 +89,7 @@ with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
|
| 108 |
choices=["Flux Pro", "Flux Dev", "Flux Schnell"],
|
| 109 |
value="Flux Pro"
|
| 110 |
)
|
| 111 |
-
prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Add your prompt here
|
| 112 |
image_size = gr.Dropdown(
|
| 113 |
choices=["square_hd", "square", "portrait_4_3", "portrait_16_9", "landscape_4_3", "landscape_16_9"],
|
| 114 |
label="Image Size",
|
|
|
|
| 5 |
import os
|
| 6 |
from fal_client import submit
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def set_fal_key(api_key):
|
| 9 |
os.environ["FAL_KEY"] = api_key
|
| 10 |
return "FAL API key set successfully!"
|
| 11 |
|
|
|
|
| 12 |
def generate_image(api_key, model, prompt, image_size, num_inference_steps, guidance_scale, num_images, safety_tolerance, enable_safety_checker, seed):
|
| 13 |
set_fal_key(api_key)
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
arguments = {
|
| 16 |
+
"prompt": prompt,
|
| 17 |
"image_size": image_size,
|
| 18 |
"num_inference_steps": num_inference_steps,
|
| 19 |
"num_images": num_images,
|
|
|
|
| 72 |
|
| 73 |
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
| 74 |
gr.HTML("""
|
| 75 |
+
<h1 align="center">FLUX.1 Image Generation</h1>
|
| 76 |
<p align="center">
|
| 77 |
<a href="https://blackforestlabs.ai/" target="_blank">[Black Forest Labs]</a>
|
| 78 |
<a href="https://blackforestlabs.ai/announcing-black-forest-labs/" target="_blank">[Blog]</a>
|
|
|
|
| 89 |
choices=["Flux Pro", "Flux Dev", "Flux Schnell"],
|
| 90 |
value="Flux Pro"
|
| 91 |
)
|
| 92 |
+
prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Add your prompt here")
|
| 93 |
image_size = gr.Dropdown(
|
| 94 |
choices=["square_hd", "square", "portrait_4_3", "portrait_16_9", "landscape_4_3", "landscape_16_9"],
|
| 95 |
label="Image Size",
|