lalashechka commited on
Commit
687077f
·
1 Parent(s): b7b8474

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -35
app.py CHANGED
@@ -10,6 +10,7 @@ from datetime import datetime
10
  import re
11
  import time
12
  import random
 
13
 
14
 
15
  def flip_text(prompt, key):
@@ -19,44 +20,69 @@ def flip_text(prompt, key):
19
  url_api1 = os.getenv("url_api1")
20
  url_api2 = os.getenv("url_api2")
21
 
 
 
 
 
 
22
  if str(key).lower() == str(key_os).lower():
23
  try:
24
- print(prompt)
25
- headers = os.getenv("headers")
26
- url_api = os.getenv("url_api")
27
-
28
- headers = eval(str(headers))
29
- json_data = {'prompt': prompt, 'n': 1,'size': '1024x1024','response_format': 'b64_json','model': 'dall-e-3','quality': 'hd',}
30
- response = requests.post(f"{url_api}", headers=headers, json=json_data)
31
- js = response.json()
32
- if "content_policy_violation" in str(js):
33
- return "https://myneuralnetworks.ru/static/img/zp.jpg"
34
- else:
35
- photo = response.json()['data'][0]['b64_json']
36
- photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
37
- return photo
 
 
 
 
38
  except:
39
- send_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
40
- url_id1 = os.getenv("url_id1")
41
- r_m = requests.post("https://myneuralnetworks.ru/get_key_dalle/", data={"key": url_id1})
42
- key_a = r_m.json()['result']
43
-
44
- headers = {'authorization': key_a}
45
- json_data = {'apiSource': 'gpt-all-tools'}
46
- response = requests.post(f'{url_api1}', headers=headers, json=json_data)
47
- chatUuid = response.json()['data']['chatUuid']
48
-
49
- json_data2 = {
50
- 'prompt': f'Нарисуй {prompt}',
51
- 'chatUuid': chatUuid,
52
- 'sendTime': send_time,
53
- 'attachments': [],
54
- }
55
-
56
- response2 = requests.post(f'{url_api2}', headers=headers, json=json_data2)
57
- url_pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
58
- urls = re.findall(url_pattern, str(response2.text))
59
- return urls[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
  else:
62
  return "https://myneuralnetworks.ru/static/img/zp2.jpg"
 
10
  import re
11
  import time
12
  import random
13
+ from bs4 import BeautifulSoup
14
 
15
 
16
  def flip_text(prompt, key):
 
20
  url_api1 = os.getenv("url_api1")
21
  url_api2 = os.getenv("url_api2")
22
 
23
+ model_gr = os.getenv("model_gr")
24
+ headers_a = os.getenv("headers_gr")
25
+ a = eval(str(headers_a))
26
+ api_gr = os.getenv("api_gr")
27
+
28
  if str(key).lower() == str(key_os).lower():
29
  try:
30
+ with closing(create_connection(f"{api_gr}", timeout=60, header=a)) as conn:
31
+ conn.send('{"fn_index":46,"session_hash":""}')
32
+ conn.send(f'{{"data":["{model_gr}",null,4096,"gpt-3.5-turbo","{prompt}","",1,1,[],null,"","1024x1024"],"event_data":null,"fn_index":46,"session_hash":""}}')
33
+ while True:
34
+ conn_s = conn.recv()
35
+ print(conn_s)
36
+ status = json.loads(conn_s)['msg']
37
+ print(status)
38
+ if status == 'estimation':
39
+ continue
40
+ if status == 'process_starts':
41
+ continue
42
+ if status == 'process_generating':
43
+ continue
44
+ if status == 'process_completed':
45
+ s = BeautifulSoup(str(conn_s), 'html.parser')
46
+ return str(s.find('img').get('src')).replace(r'\"', '')
47
+ break
48
  except:
49
+ try:
50
+ print(prompt)
51
+ headers = os.getenv("headers")
52
+ url_api = os.getenv("url_api")
53
+
54
+ headers = eval(str(headers))
55
+ json_data = {'prompt': prompt, 'n': 1,'size': '1024x1024','response_format': 'b64_json','model': 'dall-e-3','quality': 'hd',}
56
+ response = requests.post(f"{url_api}", headers=headers, json=json_data)
57
+ js = response.json()
58
+ if "content_policy_violation" in str(js):
59
+ return "https://myneuralnetworks.ru/static/img/zp.jpg"
60
+ else:
61
+ photo = response.json()['data'][0]['b64_json']
62
+ photo = Image.open(io.BytesIO(base64.decodebytes(bytes(photo, "utf-8"))))
63
+ return photo
64
+ except:
65
+ send_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
66
+ url_id1 = os.getenv("url_id1")
67
+ r_m = requests.post("https://myneuralnetworks.ru/get_key_dalle/", data={"key": url_id1})
68
+ key_a = r_m.json()['result']
69
+
70
+ headers = {'authorization': key_a}
71
+ json_data = {'apiSource': 'gpt-all-tools'}
72
+ response = requests.post(f'{url_api1}', headers=headers, json=json_data)
73
+ chatUuid = response.json()['data']['chatUuid']
74
+
75
+ json_data2 = {
76
+ 'prompt': f'Нарисуй {prompt}',
77
+ 'chatUuid': chatUuid,
78
+ 'sendTime': send_time,
79
+ 'attachments': [],
80
+ }
81
+
82
+ response2 = requests.post(f'{url_api2}', headers=headers, json=json_data2)
83
+ url_pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+'
84
+ urls = re.findall(url_pattern, str(response2.text))
85
+ return urls[0]
86
 
87
  else:
88
  return "https://myneuralnetworks.ru/static/img/zp2.jpg"