clementrof commited on
Commit
46f1835
·
verified ·
1 Parent(s): 7de7cce

Delete app3.py

Browse files
Files changed (1) hide show
  1. app3.py +0 -225
app3.py DELETED
@@ -1,225 +0,0 @@
1
- import gradio as gr
2
- import requests
3
- import time
4
- import requests
5
- import base64
6
-
7
-
8
-
9
-
10
- token = '5UAYO8UWHNQKT3UUS9H8V360L76MD72DRIUY9QC2'
11
-
12
-
13
-
14
-
15
- ##############################################################
16
- #################################################
17
-
18
- def SD_call(image_prompt, age, color, hair_color):
19
-
20
- serverless_api_id = '3g77weiulabzuk'
21
- # Define the URL you want to send the request to
22
- url = f"https://api.runpod.ai/v2/{serverless_api_id}/runsync"
23
-
24
- # Define your custom headers
25
- headers = {
26
- "Authorization": f"Bearer {token}",
27
- "Accept": "application/json",
28
- "Content-Type": "application/json"
29
- }
30
-
31
- # Define your data (this could also be a JSON payload)
32
- print("SD_processing")
33
- data = {
34
- "input": {
35
- "api": {
36
- "method": "POST",
37
- "endpoint": "/sdapi/v1/txt2img"
38
- },
39
- "payload": {
40
- "override_settings": {
41
- "sd_model_checkpoint": "CyberRealistic",
42
- "sd_vae": ""
43
- },
44
- "override_settings_restore_afterwards": True,
45
- "refiner_checkpoint": "",
46
- "refiner_switch_at": 0.8,
47
- "prompt": f"masterpiece, best quality, 8k, (looking at viewer:1.1), gorgeous, hot, seductive, {age} years old american {color} woman, (eye contact:1.1), beautiful face, hyper detailed, best quality, ultra high res, {hair_color} hair,blue eyes, photorealistic, high resolution, detailed, raw photo, 1girl,{image_prompt} ",
48
- "negative_prompt": "EasyNegative, fat, paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, ((monochrome)), ((grayscale)), bad anatomy, text, error, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, bad feet, poorly drawn face, bad proportions, gross proportions, ng_deepnegative_v1_75t, badhandsv5-neg, clothes",
49
- "seed": -1,
50
- "batch_size": 1,
51
- "steps": 30,
52
- "cfg_scale": 7,
53
- "width": 520,
54
- "height": 520,
55
- "sampler_name": "DPM++ SDE Karras",
56
- "sampler_index": "DPM++ SDE Karras",
57
- "restore_faces": False
58
- }
59
- }
60
- }
61
-
62
-
63
-
64
-
65
- # Send the POST request with headers and data
66
- response = requests.post(url, headers=headers, json=data)
67
-
68
- # Check the response
69
- if response.status_code == 200:
70
- response_data = response.json()
71
- msg_id = response_data['id']
72
- print("Message ID:", msg_id)
73
-
74
- # Poll the status until it's not 'IN_QUEUE'
75
- while response_data['status'] == 'IN_QUEUE':
76
- time.sleep(5) # Wait for 5 seconds before checking again
77
- response = requests.get(f"{url}/{msg_id}", headers=headers)
78
-
79
- try:
80
- response_data = response.json()
81
- except Exception as e:
82
- print("Error decoding JSON:", e)
83
- print("Response content:", response.text)
84
- break # Exit the loop on JSON decoding error
85
-
86
- # Check if the response contains images
87
- if 'images' in response_data.get('output', {}):
88
- base64_image = response_data['output']['images'][0]
89
- image_bytes = base64.b64decode(base64_image)
90
-
91
- # Save the image to a file
92
- image_path = f"output_image_{msg_id}.png"
93
- with open(image_path, "wb") as img_file:
94
- img_file.write(image_bytes)
95
-
96
- print(f"Image downloaded successfully: {image_path}")
97
-
98
- return image_path
99
-
100
- else:
101
- return "No images found in the response."
102
-
103
- else:
104
- # Print error message
105
- return f"Error: {response.status_code} - {response.text}"
106
-
107
-
108
-
109
-
110
- ##############################################################
111
- #################################################
112
-
113
-
114
-
115
- def LLM_call(message_log, temperature):
116
-
117
- serverless_api_id = '4whzcbwuriohqh'
118
- # Define the URL you want to send the request to
119
- url = f"https://api.runpod.ai/v2/{serverless_api_id}/run"
120
-
121
- # Define your custom headers
122
- headers = {
123
- "Authorization": f"Bearer {token}",
124
- "Accept": "application/json",
125
- "Content-Type": "application/json"
126
- }
127
-
128
-
129
-
130
- # Define your data (this could also be a JSON payload)
131
- data = {
132
-
133
- "input": {
134
- "prompt": message_log,
135
- "max_new_tokens": 4500,
136
- "temperature": 0.7,
137
- "top_k": 50,
138
- "top_p": 0.9,
139
- "repetition_penalty": 1.2,
140
- "batch_size": 8,
141
- "stop": ["</s>"]
142
- }
143
- }
144
-
145
-
146
-
147
-
148
- # Send the POST request with headers and data
149
- call = requests.post(url, headers=headers, json=data)
150
- response_data = call.json()
151
- msg_id = response_data['id']
152
- print("Message ID:", msg_id)
153
- output = "Output not available"
154
- # Poll the API until the response is ready
155
- while True:
156
- # Get the status using the message ID
157
- response = requests.get(f"https://api.runpod.ai/v2/{serverless_api_id}/status/{msg_id}", headers=headers)
158
-
159
- if response.status_code == 200:
160
- response_data = response.json()
161
- status = response_data.get('status')
162
-
163
- if status == 'COMPLETED':
164
- # Access the 'output' directly from the response
165
- output = response_data.get('output', 'Output not available')
166
- print("Response content:", output)
167
- break # Exit the loop once the response is ready
168
- elif status == 'FAILED':
169
- error_message = response_data.get('error', 'Unknown error')
170
- print("Request failed. Reason:", error_message)
171
- break # Exit the loop if the request failed
172
- else:
173
- print("Failed to get status. HTTP status code:", response.status_code)
174
-
175
- # Wait for a short time before polling again (e.g., 2 seconds)
176
- time.sleep(2)
177
-
178
- return output
179
-
180
-
181
-
182
-
183
-
184
- def Chat_call(chat,temperature):
185
- message_log = [{"role": "assistant", "content": f"I want you to act as a woman named Julie. Use colloquial language. Julie is 25 years old, she is very hot physically, she loves watching football, she loves to talk about sex. Julie loves sex and being fucked. She never refuses anything. You'll answer to a man, call him baby. Write very short answers, 15 words."},]
186
- new_message = {"role": "user", "content": chat}
187
- message_log.append(new_message)
188
- response = LLM_call(message_log, temperature)
189
- print("From Runpod:" + response)
190
- return response
191
-
192
-
193
-
194
-
195
- ########################################################
196
- #######################################################
197
-
198
-
199
-
200
- def greet(chat, image_prompt, temperature, age, color, hair_color):
201
- if image_prompt.strip():
202
- image_path = SD_call(image_prompt,age, color, hair_color)
203
- return "Image generated successfully", image_path
204
-
205
- if temperature > 3:
206
- return "You are too warm please try again", None
207
- else:
208
- text_answer = Chat_call(chat,temperature)
209
- return text_answer, None
210
-
211
- demo = gr.Interface(
212
- fn=greet,
213
- inputs=[
214
- "text",
215
- gr.Textbox(label="Image", lines=3),
216
- gr.Slider(label="Text temperature", value=1, minimum=0, maximum=2),
217
- gr.Slider(label="Age", value=22, minimum=18, maximum=75),
218
- gr.Dropdown(["asian", "white", "black", "latina"], label="Color", info="Will add more later!"),
219
- gr.Dropdown(["blond", "brune", "red", "white", "pink", "black", "blue", "green"], label="Hair color", info="Blond is cool")
220
- ],
221
- flagging_options=["blurry", "incorrect", "other"],
222
- outputs=[gr.Textbox(label="Answer", lines=3), gr.Image(label="Generated Image", type="filepath")],
223
- )
224
-
225
- demo.launch(share=True)