Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
-
import torch
|
2 |
from transformers import MBartForConditionalGeneration, MBart50Tokenizer, AutoModelForCausalLM, AutoTokenizer, pipeline
|
3 |
-
from diffusers import
|
|
|
4 |
import gradio as gr
|
5 |
-
import io
|
6 |
-
from PIL import Image
|
7 |
import os
|
|
|
8 |
|
9 |
# Load the Hugging Face API key from environment variables
|
10 |
hf_api_key = os.getenv("multimodel_token")
|
@@ -22,15 +21,15 @@ text_tokenizer = AutoTokenizer.from_pretrained(text_generation_model_name)
|
|
22 |
text_model = AutoModelForCausalLM.from_pretrained(text_generation_model_name)
|
23 |
text_generator = pipeline("text-generation", model=text_model, tokenizer=text_tokenizer)
|
24 |
|
25 |
-
# Load the
|
26 |
-
pipe =
|
27 |
-
pipe.
|
28 |
|
29 |
-
# Function to generate an image using
|
30 |
def generate_image_from_text(translated_text):
|
31 |
try:
|
32 |
print(f"Generating image from translated text: {translated_text}")
|
33 |
-
# Generate the image using the
|
34 |
image = pipe(translated_text).images[0]
|
35 |
print("Image generation completed.")
|
36 |
return image, None
|
|
|
|
|
1 |
from transformers import MBartForConditionalGeneration, MBart50Tokenizer, AutoModelForCausalLM, AutoTokenizer, pipeline
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
import torch
|
4 |
import gradio as gr
|
|
|
|
|
5 |
import os
|
6 |
+
from PIL import Image
|
7 |
|
8 |
# Load the Hugging Face API key from environment variables
|
9 |
hf_api_key = os.getenv("multimodel_token")
|
|
|
21 |
text_model = AutoModelForCausalLM.from_pretrained(text_generation_model_name)
|
22 |
text_generator = pipeline("text-generation", model=text_model, tokenizer=text_tokenizer)
|
23 |
|
24 |
+
# Load the alvdansen/flux-koda image generation model using Diffusers
|
25 |
+
pipe = StableDiffusionPipeline.from_pretrained("alvdansen/flux-koda", use_auth_token=hf_api_key)
|
26 |
+
pipe.to("cuda") # Use GPU for faster generation, if available
|
27 |
|
28 |
+
# Function to generate an image using alvdansen/flux-koda model
|
29 |
def generate_image_from_text(translated_text):
|
30 |
try:
|
31 |
print(f"Generating image from translated text: {translated_text}")
|
32 |
+
# Generate the image using the alvdansen/flux-koda model
|
33 |
image = pipe(translated_text).images[0]
|
34 |
print("Image generation completed.")
|
35 |
return image, None
|