tejani commited on
Commit
319c6e9
·
verified ·
1 Parent(s): 6ebd9b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -6,21 +6,27 @@ import random
6
  hf_token = os.getenv("HF_TOKEN")
7
 
8
  # Load the pre-built text-to-image model interface
9
- interface = gr.load("models/ZB-Tech/Text-to-Image", token=hf_token)
10
 
11
- # Function to generate a random seed and display it
12
- def generate_with_seed(prompt):
13
- seed = random.randint(0, 1000000) # Generate a random seed
14
- # Note: The pre-built interface may not accept a seed parameter directly.
15
- # This is just an example of how you might use it if you had control over the model.
16
- return f"Generated with random seed: {seed}"
 
 
 
 
 
17
 
18
- # Create a custom interface that includes the seed generation
19
  custom_interface = gr.Interface(
20
- fn=generate_with_seed,
21
- inputs="text",
22
- outputs="text", # Adjust this based on what the model actually returns (e.g., "image")
23
- title="Text-to-Image with Random Seed"
 
24
  )
25
 
26
  # Launch the interface
 
6
  hf_token = os.getenv("HF_TOKEN")
7
 
8
  # Load the pre-built text-to-image model interface
9
+ base_interface = gr.load("models/ZB-Tech/Text-to-Image", token=hf_token)
10
 
11
+ # Function to generate an image with a random seed
12
+ def generate_image_with_seed(prompt):
13
+ # Generate a random seed (for display or potential use)
14
+ seed = random.randint(0, 1000000)
15
+
16
+ # Call the pre-built interface to generate the image
17
+ # Note: This assumes the interface takes a text prompt and returns an image
18
+ image = base_interface(prompt)
19
+
20
+ # Return the image and the seed value
21
+ return image, f"Random seed used: {seed}"
22
 
23
+ # Create a custom Gradio interface
24
  custom_interface = gr.Interface(
25
+ fn=generate_image_with_seed,
26
+ inputs=gr.Textbox(label="Enter your prompt"),
27
+ outputs=[gr.Image(label="Generated Image"), gr.Textbox(label="Seed")],
28
+ title="Text-to-Image with Random Seed",
29
+ description="Generate an image from a text prompt with a random seed."
30
  )
31
 
32
  # Launch the interface