adding image gen
Browse files
app.py
CHANGED
|
@@ -1,14 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
zero = torch.Tensor([0]).cuda()
|
|
|
|
| 6 |
print(zero.device) # <-- 'cpu' 🤔
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
@spaces.GPU
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import torch
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
|
| 6 |
zero = torch.Tensor([0]).cuda()
|
| 7 |
+
|
| 8 |
print(zero.device) # <-- 'cpu' 🤔
|
| 9 |
|
| 10 |
+
client = InferenceClient()
|
| 11 |
+
image_model = 'black-forest-labs/FLUX.1-dev'
|
| 12 |
+
|
| 13 |
@spaces.GPU
|
| 14 |
+
def generate_image(input_prompt):
|
| 15 |
+
image = client.text_to_image(prompt=input_prompt, model=image_model)
|
| 16 |
+
return(image)
|
| 17 |
+
|
| 18 |
+
with gr.Blocks(title="ball") as demo:
|
| 19 |
+
|
| 20 |
+
input_prompt = gr.Textbox(label="Prompt")
|
| 21 |
+
|
| 22 |
+
text_to_image_generate_button = gr.Button("Generate")
|
| 23 |
+
|
| 24 |
+
text_to_image_output = gr.Image(label="Image", type="pil")
|
| 25 |
|
| 26 |
+
text_to_image_generate_button.click(
|
| 27 |
+
fn=generate_image,
|
| 28 |
+
inputs=input_prompt,
|
| 29 |
+
outputs=text_to_image_output
|
| 30 |
+
)
|
| 31 |
+
demo.launch()
|