Commit 6054495c authored by 余德靖's avatar 余德靖
Browse files

Upload New File

parent d8712e00
No related merge requests found
Showing with 136 additions and 0 deletions
+136 -0
import requests
import base64
from PIL import Image
from io import BytesIO
from flask import Flask, request
import requests
import json
app = Flask(__name__)
def stable_diffusion(data):
# 设置stable diffusion 的端口x
url = "http://stablediffusion.rejo9.com/sdapi/v1/txt2img"
response = requests.post(url, json=data)
print('response',response.text)
if response.status_code == 200:
data = json.loads(response.text)
init_images = data.get("images")
# print(init_images)
return init_images
def chatsd(prompt,art_style=None):
# 翻译员prompt
translation_prompt = prompt
translation_prompt = f"I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. My first sentence is {prompt}"
prompt_js = {
"prompt": translation_prompt
}
response = requests.post("https://test-irisbot.shauetech.com/gptProxyService/callgpt", json=prompt_js)
parsed_response = json.loads(response.text)
content = parsed_response["data"]
json_obj = json.loads(content)
content_value = json_obj["choices"][0]["message"]["content"]
# 翻译后的英文
translation_prompt = content_value
print('翻译内容:\n',translation_prompt)
# 判断是否传入艺术风格
if art_style is None:
create_prompt =f"Stable Diffusion is an AI art generation model. \
Below is a list of prompts that can be used to generate images with Stable Diffusion:\
- portait of a homer simpson archer shooting arrow at forest monster, front game card, drark, marvel comics, dark, intricate, highly detailed, smooth, artstation\
- pirate, concept art, deep focus, fantasy, intricate, highly detailed, digital painting, artstation, matte, sharp focus, illustration, \
art by magali villeneuve, chippy, ryan yee, rk post, clint cearley, daniel ljunggren, zoltan boros, gabor szikszai, howard lyon,\
steve argyle, winona nelson \
- ghost inside a hunted room, loish and ross tran and rossdraws and sam yang and samdoesarts and artgerm,\
digital art, highly detailed, intricate, sharp focus, Trending on Artstation HQ, deviantart, unreal engine 5, 4K UHD image \
- red dead redemption 2, cinematic view, epic sky, detailed, concept art, low angle, high detail, warm lighting, volumetric, godrays,\
vivid, beautiful, trending on artstation,huge scene, grass\
- a fantasy style portrait painting of rachel lane / alison brie hybrid in the style of francois boucher oil painting unreal 5 daz. \
rpg portrait, extremely detailed artgerm greg rutkowski alphonse mucha greg hildebrandt tim hildebrandt\
- athena, greek goddess, claudia black, bronze greek armor, owl crown, \
d & d, fantasy, intricate, portrait, highly detailed, headshot, digital painting, trending on artstation, concept art, sharp focus, illustration \
- closeup portrait shot of a large strong female biomechanic woman in a scenic scifi environment, intricate, elegant,\
highly detailed, centered, digital painting, artstation, concept art, smooth, sharp focus, warframe, illustration, thomas kinkade,\
tomasz alen kopera, peter mohrbacher, donato giancola, leyendecker, boris vallejo \
- ultra realistic illustration of steve urkle as the hulk, intricate, elegant, highly detailed, digital painting, artstation, concept art, \
smooth, sharp focus, illustration, art by artgerm and greg rutkowski and alphonse mucha \
I want you to write me a detailed prompts exactly about the idea written after IDEA. Follow the structure of the example prompts. This means a very short description of the scene, followed by modifiers divided by commas to alter the mood, style, lighting, and more. IDEA: {translation_prompt}",
else:
create_prompt = "Stable Diffusion is an AI art generation model. Below is a list of prompts that can be used to generate images with Stable Diffusion:- portait of a homer simpson archer shooting arrow at forest monster, front game card, drark, marvel comics, dark, intricate, highly detailed, smooth, artstation\
- pirate, concept art, deep focus, fantasy, intricate, highly detailed, digital painting, artstation, matte, sharp focus, illustration, \
art by magali villeneuve, chippy, ryan yee, rk post, clint cearley, zoltan boros, , howard lyon,steve argyle, winona nelson \
- a drawing of a house with a lot of windows, concept art by toriyama sekien, pixiv, maximalism, concept art, official art, maximalist ,\
digital art, highly detailed, intricate, sharp focus, Trending on Artstation HQ, deviantart, unreal engine 5, 4K UHD image \
- red dead redemption 2, cinematic view, epic sky, detailed, concept art, low angle, high detail, warm lighting, volumetric, godrays,\
vivid, beautiful, trending on artstation, by jordan grimmer, huge scene, grass, art greg rutkowski \
- a fantasy style portrait painting of rachel lane / alison brie hybrid in the style of francois boucher oil painting unreal 5 daz. \
rpg portrait\
- athena, greek goddess, claudia black, art by artgerm and greg rutkowski and magali villeneuve, bronze greek armor, owl crown, \
d & d, fantasy, intricate, portrait, highly detailed, headshot, digital painting, trending on artstation, concept art, sharp focus, illustration \
- closeup portrait shot of a large strong female biomechanic woman in a scenic scifi environment, intricate, elegant,\
highly detailed, centered, digital painting, artstation, concept art, smooth, sharp focus, warframe, illustration, thomas kinkade,\
tomasz alen kopera, peter mohrbacher, donato giancola, leyendecker, boris vallejo \
- ultra realistic illustration of steve urkle as the hulk, intricate, elegant, highly detailed, digital painting, artstation, concept art, \
smooth, sharp focus, illustration, art by artgerm and greg rutkowski and alphonse mucha \
I want you to write me a detailed prompts exactly about the idea written after IDEA\
. Follow the structure of the example prompts. This means a very short description of the scene, followed by modifiers divided by commas to alter the mood, style, lighting, and more ,And also I want this prompt's painting type is {art_style} . IDEA: {translation_prompt}"
prompt_js = {
"prompt": create_prompt
}
response = requests.post("https://test-irisbot.shauetech.com/gptProxyService/callgpt", json=prompt_js)
parsed_response = json.loads(response.text)
content = parsed_response["data"]
json_obj = json.loads(content)
# 返回对应的 prompt 内容
prompt_response = json_obj["choices"][0]["message"]["content"]
char_to_remove = ","
# 使用 replace() 方法删除指定的字符
new_string = prompt_response.replace(char_to_remove, "IDEA:")
print('new_string')
print(new_string)
data = {"prompt": new_string,
"negative_prompt":"lowres, error, cropped, worst quality, low quality, jpeg artifacts, out of frame, watermark, signature,deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing,text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated,extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy,bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck"}
# print(data)
# print(type(data))
print('参数\n',data)
base = stable_diffusion(data=data)
return base
# # 将翻译结果传递给 prompt 生成器
# trans_data = eval(trans_result)[0]['result']
# prompt_data = {'prompt':trans_data}
# url2 = 'http://localhost:5002/genprompt'
# # response = requests.post(url, json=prompt_data)
# response_prompt = requests.post(url2, json=prompt_data)
# trans_result = response_prompt.json()
# # json_data = json.loads(json_str)
# response_text = trans_result['response_text']
# response_list = response_text.split('\n')
# response_list_cleaned = [s.strip('- ') for s in response_list]
# print(response_list_cleaned)
@app.route("/chatgpt", methods=["POST"])
def main_sdgpt():
prompt = request.json.get('prompt')
# print(request.json)
# print(type(request.json))
art_style = request.json.get('art_style')
base_64 = chatsd(prompt,art_style=art_style)
return {"image":base_64}
if __name__ == "__main__":
app.run(debug=True,port=5001)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment