AbhinavKrishnan36 commited on
Commit
f9d8220
1 Parent(s): 43c1315

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -1,24 +1,34 @@
1
  import gradio as gr
2
  import torch
3
- from diffusers import StableDiffusion3Pipeline
4
  import os
 
5
  from huggingface_hub import InferenceApi
6
 
7
-
8
- # Retrieve Hugging Face API key from environment variables
9
  hf_api_key = os.getenv("PRODIGY_GA_02")
 
 
 
 
 
10
 
11
- # Load model with authentication token
 
 
 
 
12
  model_id = "stabilityai/stable-diffusion-3.5-medium"
13
  pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium")
14
 
15
  pipe.to("cuda")# If you have GPU access; otherwise, use "cpu"
16
 
17
- # Define Gradio interface function
 
 
18
  def generate_image(prompt):
19
  images = pipe(prompt).images
20
  return images[0]
21
 
 
22
  # Create Gradio UI
23
  iface = gr.Interface(
24
  fn=generate_image,
@@ -29,4 +39,4 @@ iface = gr.Interface(
29
  )
30
 
31
  # Launch the interface
32
- iface.launch()
 
1
  import gradio as gr
2
  import torch
 
3
  import os
4
+ from diffusers import StableDiffusion3Pipeline
5
  from huggingface_hub import InferenceApi
6
 
 
 
7
  hf_api_key = os.getenv("PRODIGY_GA_02")
8
+ if hf_api_key is None:
9
+ raise ValueError("Hugging Face API key 'PRODIGY_GA_02' not found. Ensure it is set as a secret.")
10
+
11
+ # Initialize the Hugging Face API with the restricted model and token
12
+ inference = InferenceApi(repo_id="stabilityai/stable-diffusion-3.5-medium", token=hf_api_key)
13
 
14
+ # Example inference request
15
+ response = inference(inputs="Your input text here")
16
+ print(response)
17
+
18
+ # Load model
19
  model_id = "stabilityai/stable-diffusion-3.5-medium"
20
  pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3.5-medium")
21
 
22
  pipe.to("cuda")# If you have GPU access; otherwise, use "cpu"
23
 
24
+
25
+
26
+ # Define Gradio interface
27
  def generate_image(prompt):
28
  images = pipe(prompt).images
29
  return images[0]
30
 
31
+
32
  # Create Gradio UI
33
  iface = gr.Interface(
34
  fn=generate_image,
 
39
  )
40
 
41
  # Launch the interface
42
+ iface.launch()