Leeps commited on
Commit
10a713a
1 Parent(s): 3663cfe

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. .env +2 -0
  2. api/index.py +8 -9
.env ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ REPLICATE_API_TOKEN=r8_DAzyOBdCwUdt0b26ZMPWLyvyHTh55uh2Lwb3c
2
+ OPENAI_API_KEY=sk-proj-6lTXmIwTYmNo7uUpQwujT3BlbkFJDMVzyH5hzblFbgYLLMCP
api/index.py CHANGED
@@ -46,7 +46,7 @@ def call_openai(pil_image):
46
  {
47
  "role": "user",
48
  "content": [
49
- {"type": "text", "text": "You are a product designer. I've attached a moodboard here. In one sentence, what do all of these elements have in common? Answer from a design language perspective, if you were telling another designer to create something similar, including any repeating colors and materials and shapes and textures"},
50
  {
51
  "type": "image_url",
52
  "image_url": {
@@ -78,14 +78,12 @@ def image_classifier(moodboard, prompt):
78
  pil_image = Image.fromarray(moodboard.astype('uint8'))
79
 
80
  openai_response = call_openai(pil_image)
81
- openai_response = openai_response.replace('moodboard', '')
82
- openai_response = openai_response.replace('share', '')
83
- openai_response = openai_response.replace('unified', '')
84
  else:
85
  raise gr.Error(f"Please upload a moodboard to control image generation style")
86
 
87
  input = {
88
- "prompt": "high quality render of " + prompt + ", " + openai_response[12:],
89
  "output_format": "jpg"
90
  }
91
 
@@ -118,16 +116,17 @@ def image_classifier(moodboard, prompt):
118
  except Exception as e:
119
  raise gr.Error(f"Second image download failed: {e}")
120
 
121
- # Call Stable Diffusion API with the response from OpenAI
122
  input = {
123
  "width": 768,
124
  "height": 768,
125
- "prompt": "high quality render of " + prompt + ", " + openai_response[12:],
126
- "negative_prompt": "worst quality, low quality, illustration, 2d, painting, cartoons, sketch, logo, buttons",
127
  "refine": "expert_ensemble_refiner",
128
  "apply_watermark": False,
129
  "num_inference_steps": 25,
130
- "num_outputs": 2
 
131
  }
132
 
133
  output = replicate.run(
 
46
  {
47
  "role": "user",
48
  "content": [
49
+ {"type": "text", "text": "You are a product designer. I've attached a moodboard here. In one sentence, what do all of these elements have in common? Answer from a design language perspective, if you were telling another designer to create something similar, including any repeating colors and materials and shapes and textures. This is for a single product, so respond as though you're applying them to a single object. Reply with a completion to the following (don't include these words please, just the rest): [A render of an object which] [your response]. Do NOT include 'A render of an object which' in your response."},
50
  {
51
  "type": "image_url",
52
  "image_url": {
 
78
  pil_image = Image.fromarray(moodboard.astype('uint8'))
79
 
80
  openai_response = call_openai(pil_image)
81
+
 
 
82
  else:
83
  raise gr.Error(f"Please upload a moodboard to control image generation style")
84
 
85
  input = {
86
+ "prompt": "high quality render of a " + prompt + " which " + openai_response + ", minimalist and simple mockup on a white background",
87
  "output_format": "jpg"
88
  }
89
 
 
116
  except Exception as e:
117
  raise gr.Error(f"Second image download failed: {e}")
118
 
119
+ # Call SDXL API with the response from OpenAI
120
  input = {
121
  "width": 768,
122
  "height": 768,
123
+ "prompt": "centered high quality render of a " + prompt + " which " + openai_response + ' centered on a plain white background',
124
+ "negative_prompt": "worst quality, low quality, illustration, 2d, painting, cartoons, sketch, logo, buttons, markings, text, wires, complex, screws, nails, construction",
125
  "refine": "expert_ensemble_refiner",
126
  "apply_watermark": False,
127
  "num_inference_steps": 25,
128
+ "num_outputs": 2,
129
+ "guidance_scale": 8.5
130
  }
131
 
132
  output = replicate.run(