Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 마이봇#핸드폰대체#
- 마이봇#chatgpt#ai#인공지능
- 쇼핑몰관리시스템#매입관리#시트메타#매입채널#엑셀업로드
- 로우코드#ERP#관리시스템#상품관리#선택박스#자동화프로그램
- #비트코인 #이더리움 #리플 #솔라나 #알트코인 #코인뉴스 #가상자산 #암호화폐투자 #고래투자자 #스테이블코인 #BTC #ETH #XRP #SOL #코인하락 #투자전략
- 비트코인 #이더리움 #리플 #솔라나 #알트코인 #코인뉴스 #가상자산 #암호화폐투자 #고래투자자 #스테이블코인 #BTC #ETH #XRP #SOL #코인하락 #투자전략
- 비트코인 #이더리움 #암호화폐 #코인시황 #미국경제 #PCE지표 #연준 #금리인하 #인플레이션 #가상자산투자 #코인뉴스 #티스토리블로그
- #비트코인 #이더리움 #암호화폐 #블록체인 #가상자산 #미국GDP #기관투자 #한미정상회담 #디지털자산 #코인전망
- 펫버틀러#서버연동#프로필등록#로그인서버연동#이미지#동영상#업로드용 화면#앱개발#플러터#반려생활#로딩바#loading bar#
- 로우코드#lowcode#erp#관리시스템#시트메이트#시트메타#엑셀업로드#엑셀다운로드#그리드#데이터관리#생산관리시스템#로그관리#히스토리#입력체크
- #창작#SNS#스포츠#반려동물#연애#과제#레시피#활동#건강#운세#글쓰기#비즈니스 #AI비서#챗GPT#CHATGPT
- #비트코인 #이더리움 #트럼프코인 #암호화폐뉴스 #코인시황 #일본디지털화폐 #디파이 #HBAR #코인투자 #이더리움전망
- 커피#그라인더#통돌이 오픈 #로스팅#드립커피#생두#원두
- 마이봇#pdf챗봇#상담챗봇#faq챗봇#chatgpt#랭체인#llm
- PDF#챗봇검색#서비스#GPT4#PGT3.5#GPT#랭체인#챗봇#CHATBOT#LLM#문서검색
- 11만4천 달러
- 플러터#sms#mms#문자보내기
- 비트코인 #이더리움 #암호화폐 #가상자산 #코인시황 #코인투자 #ETF #스테이킹 #체인링크 #리플 #페이코인 #기관투자 #한미정상회담 #블록체인 #투자전망
- #광복절 #제80주년광복절 #순국선열 #애국지사 #비트코인 #이더리움 #가상자산 #코인투자 #암호화폐 #ETF #현물ETF #자금유입 #자동매매 #업비트 #업비트API #트레이딩 #PPI #미국물가지표 #인플레이션 #금리인하 #빅컷 #트럼프 #나스닥 #거시경제 #솔라나 #SEC #가상자산규제 #투자전략 #리스크관리 #분할매수 #분할매도
- 마이봇#문서챗봇#PDF#TEXT#유투브#챗봇만들기#랭체인# langchain#벡터데이터#자료검색#챗GPT#GPT4#챗지피티
- flutter#sqlite#chatGPT#
- 마이봇#아이폰#아이폰심사#IT고시#
- 비트코인 #암호화폐 #코인투자 #가상화폐 #이더리움 #알트코인 #코인뉴스 #투자전략 #코벡스 #코인계산기
- PDF검색#PDF검색챗봇#NEXTJS#스터디#스타트업#랭체이#langchain#prisma#sqlite#
- #비트코인 #암호화폐 #코인투자 #가상화폐 #이더리움 #알트코인 #코인뉴스 #투자전략 #코벡스 #코인계산기
- 블로그#구글노출#걸리는시간#돈벌기#블러그운영
- flutter#채팅창@메모창#url링크#날짜추가
- 메타인지#그릿#개발자#꾸준함
- 마이봇#API 설정
- 광동온더그린#프랜즈#가상CC#스크린골프#
Archives
- Today
- Total
혼자서 앱 만드는 개발자 함께하는 AI 세상
스테이블 디퓨전 파이프 라인 통해 파이썬 으로 웹구축 본문
반응형
이미지생성형 ai 스테이블 디퓨전으로 간단하게 서비스 해보고 싶은 마음에 구글링를 통해 만들어 보고 있다구글 코랩에서 작업해보고 잘되면 간단히 집에 있는 게이밍 pc돌려서 서비스를 시작 해보고 싶다.
아직 마이봇은 텍스트 기반 생성형 ai 만 지원하고 있어서 이미지 생성 ai 를 적용하면 좋을 것 같다.
작업 환경
우선 코랩에서 설치를 위해 conda 를 쓸수 있도록 인스톨한다.
!pip install -q condacolab
import condacolab
condacolab.install()
import sys
print(sys.executable)
스테이블 디퓨전 설치 xformers 설치
!conda create -n stable_diffusion python=3.10
!conda activate stable_diffusion
!conda install transformers xformers torch diffusers -c pytorch -c huggingface
#If you want to use pip
!pip install transformers xformers torch diffusers
스테이블 디퓨전 파이프라인 설치
import torch
from diffusers import DiffusionPipeline
from xformers.ops import MemoryEfficientAttentionFlashAttentionOp
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
# Workaround for not accepting attention shape using VAE for Flash Attention
pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None)
이젠 테스트 해보자
from PIL import Image
image=pipe("An image of a squirrel in Picasso style").images[0]
image.save('squirrel.png')
이미지가 잘나오는것 을 알수있다..
이젠 이미지 to 이미지 imageToImage 예제 소스를 적용해보자
import requests
import torch
from PIL import Image
from io import BytesIO
from diffusers import StableDiffusionImg2ImgPipeline
device = "cuda"
model_id_or_path = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe = pipe.to(device)
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((768, 512))
prompt = "A fantasy landscape, trending on artstation"
images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images
images[0].save("fantasy_landscape.png")
전에 만든 다람쥐를 image to image 적용 위에 소스에서 보이는 fantasy png 파일로 적용 해보고
#StableDiffusionImg2ImgPipeline: def decorate_context(*args, **kwargs)
#https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.pyfrom PIL import Image
import PIL
init_image = Image.open(r"fantasy_landscape.png")
image=pipe("An image of a squirrel in Picasso style" ,image=init_image, strength=0.75, guidance_scale=7.5).images[0]
print(type(image))
# Importing Image module from PIL package
from PIL import Image
import PIL
# creating a image object (main image)
#im1 = Image.open(r"C:\Users\System-Pc\Desflower1.jpg")
# save a image using extension
im1 = image.save("geeks.jpg")
웨서비스를 위해 flask 로 테스트 해봄
# Run a python(flask)-based web service in your note book
# You can reload this cell to restart the server if you make changes
default_port = 6060
from werkzeug.serving import make_server
from flask import Flask,make_response
import threading
class ServerThread(threading.Thread):
def __init__(self, app, port):
threading.Thread.__init__(self)
self.port = port
self.srv = make_server('127.0.0.1', port, app)
self.ctx = app.app_context()
self.ctx.push()
def run(self):
print('starting server on port:',self.port)
self.srv.serve_forever()
def shutdown(self):
self.srv.shutdown()
def start_server(port=default_port):
global server
if 'server' in globals() and server:
print('stopping server')
stop_server()
app = Flask('myapp')
# you can add your own routes here as needed
@app.route("/")
def hello():
# A wee bit o'html
image=pipe("An image of a squirrel in Picasso style" ,image=init_image, strength=0.75, guidance_scale=7.5).images[0]
#pipe("An image of bear in Korean style").images[0]
return '<h1 style="color:red;">Hello From Flask!</h1>'
server = ServerThread(app,port)
server.start()
@app.route('/file')
def local_photo():
print('executing local_photo...')
with open('geeks.jpg', 'rb') as image_file:
def wsgi_app(environ, start_response):
start_response('200 OK', [('Content-type', 'image/jpeg')])
return image_file.read()
return make_response(wsgi_app)
def stop_server():
global server
if server:
server.shutdown()
server = None
# Start the server here
start_server()
확인해 보고 잘되는지 그럼 다음엔 테스트로 input 거나 이미지를 올려서 이미지를 리턴받을 수 있게 구성해볼 수 있다.
!wget http://localhost:6060/file
728x90
반응형
'딥러닝 머신러닝' 카테고리의 다른 글
플러터 카메라 실시간데이터 처리를 위한 startImageStream (0) | 2023.07.27 |
---|---|
Yolov8 을 이용한 커스텀 데이터 훈련영상 (0) | 2023.07.07 |
tensorflowjs 통해 첫 번째 웹 서비스 'Teachable Machine' 만들기 (0) | 2023.06.20 |
파이썬 flask에서 텐서플로 숫자 맞추기 웹서비스 해보기 (0) | 2023.06.20 |
텐서플(tenserflow)로 시작 해보기 (3) | 2023.06.18 |
Comments