GenAIJake commited on
Commit
f2b6373
·
1 Parent(s): 59ad75b

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +28 -8
  2. requirements.txt +3 -1
app.py CHANGED
@@ -1,26 +1,46 @@
1
  import gradio as gr
2
  import requests
3
  import os
 
 
4
 
5
  def generate(prompt):
6
  API_URL = "https://api-inference.huggingface.co/models/GenAIJake/d3xt3r-l1tt13-dachshund"
7
- headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
 
 
 
 
 
 
 
 
 
8
  payload = {
9
- "inputs": prompt,
10
  "parameters": {
11
  "num_inference_steps": 30,
12
  "guidance_scale": 7.5,
13
- "negative_prompt": ["blurry, bad quality"]
 
14
  }
15
  }
16
- response = requests.post(API_URL, headers=headers, json=payload)
17
- return response.json()
 
 
 
 
 
 
18
 
 
19
  demo = gr.Interface(
20
  fn=generate,
21
- inputs="text",
22
- outputs="image",
23
- title="D3xt3r L1tt13 Dachshund Generator"
 
24
  )
25
 
26
  demo.launch()
 
1
  import gradio as gr
2
  import requests
3
  import os
4
+ from PIL import Image
5
+ import io
6
 
7
  def generate(prompt):
8
  API_URL = "https://api-inference.huggingface.co/models/GenAIJake/d3xt3r-l1tt13-dachshund"
9
+ headers = {
10
+ "Authorization": f"Bearer {os.getenv('HF_TOKEN')}",
11
+ "Content-Type": "application/json",
12
+ "x-use-cache": "false", # Disable caching for new generations
13
+ "x-wait-for-model": "true" # Wait for model if it needs to load
14
+ }
15
+
16
+ # Add the trigger words to the prompt
17
+ full_prompt = f"d3xt3r-l1tt13 Dachshund, {prompt}"
18
+
19
  payload = {
20
+ "inputs": full_prompt,
21
  "parameters": {
22
  "num_inference_steps": 30,
23
  "guidance_scale": 7.5,
24
+ "negative_prompt": "blurry, bad quality, worst quality, low quality",
25
+ "seed": None # Random seed for each generation
26
  }
27
  }
28
+
29
+ try:
30
+ response = requests.post(API_URL, headers=headers, json=payload)
31
+ # Convert the binary response to a PIL Image
32
+ image = Image.open(io.BytesIO(response.content))
33
+ return image
34
+ except Exception as e:
35
+ return f"Error generating image: {str(e)}"
36
 
37
+ # Create the Gradio interface
38
  demo = gr.Interface(
39
  fn=generate,
40
+ inputs=gr.Textbox(label="Enter your prompt"),
41
+ outputs=gr.Image(label="Generated Image"),
42
+ title="D3xt3r L1tt13 Dachshund Generator",
43
+ description="Generate images of a cute dachshund character. The model will automatically add 'd3xt3r-l1tt13 Dachshund' to your prompt."
44
  )
45
 
46
  demo.launch()
requirements.txt CHANGED
@@ -3,4 +3,6 @@ diffusers
3
  invisible_watermark
4
  torch
5
  transformers
6
- xformers
 
 
 
3
  invisible_watermark
4
  torch
5
  transformers
6
+ xformers
7
+ gradio>=4.43.0
8
+ requests