unfavalen commited on
Commit
021585a
·
verified ·
1 Parent(s): 54aea31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -56
app.py CHANGED
@@ -1,63 +1,12 @@
1
  import gradio as gr
2
- from transformers import AutoProcessor, AutoModelForImageGeneration
3
- import torch
4
- import random
5
-
6
- # Check if GPU is available
7
- device = "cuda" if torch.cuda.is_available() else "cpu"
8
-
9
- # Load the model and processor (replace with your actual model)
10
- def load_model():
11
- model_name = "robiai/picasoe" # Replace with the actual model name
12
- processor = AutoProcessor.from_pretrained(model_name)
13
- model = AutoModelForImageGeneration.from_pretrained(model_name).to(device)
14
- return processor, model
15
-
16
- processor, model = load_model()
17
 
18
  def generate_image(prompt, image_size="Default", num_inference_steps=28, seed="random", guidance_scale=3.5, sync_mode=True, num_images=1):
19
- try:
20
- # Set seed for reproducibility
21
- if seed == "random":
22
- seed_value = random.randint(0, 2**32 - 1)
23
- else:
24
- seed_value = int(seed)
25
- torch.manual_seed(seed_value)
26
-
27
- # Map image size to dimensions (customize as needed)
28
- size_mapping = {
29
- "Default": (512, 512),
30
- "Square": (512, 512),
31
- "Square HD": (1024, 1024),
32
- "Portrait 3:4": (768, 1024),
33
- "Portrait 9:16": (576, 1024),
34
- "Landscape 4:3": (1024, 768),
35
- "Landscape 16:9": (1024, 576),
36
- "Custom": (512, 512) # Default for custom
37
- }
38
- width, height = size_mapping[image_size]
39
-
40
- # Prepare inputs for the model
41
- inputs = processor(text=prompt, return_tensors="pt").to(device)
42
-
43
- # Generate images
44
- with torch.no_grad():
45
- outputs = model.generate(
46
- **inputs,
47
- num_inference_steps=num_inference_steps,
48
- guidance_scale=guidance_scale,
49
- num_images_per_prompt=num_images,
50
- output_type="pil"
51
- )
52
-
53
- # Return the first generated image (or handle multiple images as needed)
54
- return outputs[0] if num_images == 1 else outputs
55
-
56
- except Exception as e:
57
- print(f"Error during image generation: {e}")
58
- return None
59
 
60
- # Gradio Interface
61
  with gr.Blocks(title="Picasoe") as demo:
62
  gr.Markdown("# Picasoe")
63
  gr.Markdown("Convert your ideas into jaw-dropping visuals.")
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def generate_image(prompt, image_size="Default", num_inference_steps=28, seed="random", guidance_scale=3.5, sync_mode=True, num_images=1):
4
+ # Load the model (assuming it supports these parameters)
5
+ model = gr.load("models/robiai/picasoe", provider="hf-inference")
6
+ # Implement image generation logic here
7
+ # Return the generated image
8
+ pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
 
10
  with gr.Blocks(title="Picasoe") as demo:
11
  gr.Markdown("# Picasoe")
12
  gr.Markdown("Convert your ideas into jaw-dropping visuals.")