ikmalsaid commited on
Commit
56fd4d2
1 Parent(s): 07c4bcc
Files changed (1) hide show
  1. kalam_data.py +10 -3
kalam_data.py CHANGED
@@ -20,10 +20,17 @@ theme_list = theme.keys()
20
  layer_list = layer.keys()
21
  surah_list = [theme[key]['surah'] for key in theme]
22
 
23
- import gradio as ui; import requests, logging, os; from io import BytesIO
24
  from PIL import Image, ImageEnhance; from requests.exceptions import *; import concurrent.futures
25
  logging.basicConfig(level=logging.DEBUG)
26
 
 
 
 
 
 
 
 
27
  def theme_change(a, i: ui.SelectData):
28
  print(f"Theme changed -> {a}")
29
  return ui.Dropdown(value=theme[a]['surah'])
@@ -31,9 +38,9 @@ def theme_change(a, i: ui.SelectData):
31
  def stella(surah, mode):
32
  data = {
33
  'model_version': (None, '1'),
34
- 'prompt': (None, theme[surah]['prompt']),
35
  'style_id': (None, '128'),
36
- 'negative_prompt': (None, 'hands, face, eyes, legs, watermark, text, duplicate, double, bad, ugly, bad quality, naked, nude, sexy'),
37
  'aspect_ratio': (None, '1:1'),
38
  'high_res_results': (None, '1'),
39
  'cfg': (None, '9.5'),
 
20
  layer_list = layer.keys()
21
  surah_list = [theme[key]['surah'] for key in theme]
22
 
23
+ import gradio as ui; import requests, logging, os, json; from io import BytesIO
24
  from PIL import Image, ImageEnhance; from requests.exceptions import *; import concurrent.futures
25
  logging.basicConfig(level=logging.DEBUG)
26
 
27
+ def expand(expand):
28
+ pfix = '(The prompt must intricately describe every part of the image in concrete, objective detail. THINK about what the end goal of the description is, and extrapolate that to what would make satisfying images.)'
29
+ head = {'Content-Type': 'application/json'}
30
+ body = json.dumps({"topic": f"{expand} {pfix}", "word_count": 30, "writing_mode": "Simple", "story_genre": "Descriptive"})
31
+ try: return requests.post(url=os.getenv('gpt4'), headers=head, data=body, timeout=15).json()['story']
32
+ except Exception as e: print(f"Expansion error: {e}"); return expand
33
+
34
  def theme_change(a, i: ui.SelectData):
35
  print(f"Theme changed -> {a}")
36
  return ui.Dropdown(value=theme[a]['surah'])
 
38
  def stella(surah, mode):
39
  data = {
40
  'model_version': (None, '1'),
41
+ 'prompt': (None, expand(theme[surah]['prompt'])),
42
  'style_id': (None, '128'),
43
+ 'negative_prompt': (None, 'hands, jpeg'),
44
  'aspect_ratio': (None, '1:1'),
45
  'high_res_results': (None, '1'),
46
  'cfg': (None, '9.5'),