Skip to content

Commit

Permalink
code upload
Browse files Browse the repository at this point in the history
  • Loading branch information
NICESONY committed Oct 11, 2024
1 parent 7f37f7c commit adc2049
Show file tree
Hide file tree
Showing 42 changed files with 381 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,10 @@ Code/code/ML/sql_app/templates/create_record.html
Code/code/ML/sql_app/templates/records.html
Code/code/Readme.md
Code/code/이미지로부터 영상생성.py
Code/code/ML/real_main.py
Code/code/ML/main_01.py
Code/code/main.py
Code/code/ML/Readme.md
Code/code/ML/SON/pipeline/crawl/crawling.py
Code/code/ML/SON/pipeline/dataset/식당/Image_1.JPG
Code/code/ML/SON/pipeline/dataset/식당/Image_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions Code/code/ML/SON/pipeline/frontend/css/wirtingInputarea.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
*,
body {
margin: 0;
padding: 0;
box-sizing: border-box;
}

.contentbox {
width: 390px;
margin: auto;
height: 100%;

}

@font-face {
font-family: 'Pretendard-Regular';
src: url('https://fastly.jsdelivr.net/gh/Project-Noonnu/[email protected]/Pretendard-Regular.woff') format('woff');
font-weight: 400;
font-style: normal;
}

section.tags {
width: 88%;
display: flex;
justify-content: start;
align-items: center;
margin: auto;


}

button.tag {
margin: 4px;
width: 76px;
height: 30px;
flex-shrink: 0;
border-radius: 43px;
border: 1.5px solid #F29272;
color: #F29272;
cursor: pointer;
background-color: #fff;
font-family: 'Pretendard-Regular';
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: normal;
}

button.tag-add {
width: 30px;
height: 30px;
background-image: url(../icon/plusicon.svg);
background-size: cover;
border: none;
background-color: #fff;
}

#notchs {
margin: 4px;
width: 76px;
height: 30px;
flex-shrink: 0;
border-radius: 43px;
border: 1.5px solid #ADAAAA;
color: #ADAAAA;
cursor: pointer;
background-color: #fff;
font-family: 'Pretendard-Regular';
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: normal;
}

.container {
width: 390px; /* 고정 너비 설정 */
margin: 0 auto;
background-color: white;
padding: 20px;
border-radius: 10px;
}

.color-picker {
display: flex;
justify-content: space-between;
margin-bottom: 15px;
}

.color-button {
width: 40px;
height: 40px;
border: none;
border-radius: 5px;
cursor: pointer;
}

.input-field, .textarea {
width: 100%; /* 부모 요소의 너비에 딱 맞게 설정 */
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
}

.textarea {
height: 100px; /* 높이 설정 */
}

.save-button {
width: 100%;
padding: 10px;
background-color: #F29272;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
10 changes: 10 additions & 0 deletions Code/code/ML/SON/pipeline/frontend/icon/leading-iconnewrecord.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Code/code/ML/SON/pipeline/frontend/icon/plusicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions Code/code/ML/SON/pipeline/frontend/icon/trailing-iconnewrecord.svg
77 changes: 77 additions & 0 deletions Code/code/ML/SON/pipeline/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!--css-->
<link rel="stylesheet" href="./css/setup.css">
<link rel="stylesheet" href="./css/headersubpage.css">
<link rel="stylesheet" href="./css/wirtingInputarea.css">
<link rel="stylesheet" href="./css/writingcard.css">
<!--js-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
<script src="./js/wirtingswiper.js" defer></script>
</head>

<body>
<div class="contentbox">
<header>
<div class="headerbox">
<div class="icon">
<a href="/"><img src="./icon/leading-iconnewrecord.svg" alt="Icon"></a>
</div>
<div class="header-text">
<p>새로운 기록</p>
</div>
<div class="icon">
<a href="/"><img src="./icon/trailing-iconnewrecord.svg" alt="Icon"></a>
</div>
</div>
</header>
<div class="topgap"></div>
<div class="swiper">
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="swipercontent">
</div>
</div>
<div class="swiper-slide">
<div class="swipercontent"></div>
</div>
<div class="swiper-slide">
<div class="swipercontent">
<div class="imgupload">
<label for="photo-upload" class="photo-label">
<input type="file" id="photo-upload" accept="image/*">
</label>
</div>
</div>
</div>
</div>
</div>
<div class="swiper-pagination"></div>

</div>
<section class="tags">
<button class="tag"># 즐거움</button>
<button class="tag" id="notchs"># 아쉬움</button>
<button class="tag"># 편안함</button>
<button class="tag-add"><i class="fa fa-plus"></i></button>
</section>

<div class="container">
<input type="text" placeholder="날짜" class="input-field">
<input type="text" placeholder="위치" class="input-field">
<input type="text" placeholder="작성자" class="input-field">
<textarea placeholder="내용을 입력하세요..." class="textarea"></textarea>
<button class="save-button">저장하기</button>
</div>
<script src="script.js"></script>
</body>
</div>

</html>
37 changes: 37 additions & 0 deletions Code/code/ML/SON/pipeline/frontend/js/wirtingswiper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

var mySwiper = new Swiper ('.swiper-container', {
speed: 400,
spaceBetween: 30,
initialSlide: 0,
//truewrapper adoptsheight of active slide
autoHeight: false,
// Optional parameters
direction: 'horizontal',
loop: true,
// delay between transitions in ms
autoplay: 5000,
autoplayStopOnLast: false, // loop false also
// If we need pagination
pagination: '.swiper-pagination',
paginationType: "bullets",

// Navigation arrows
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',

// And if we need scrollbar
//scrollbar: '.swiper-scrollbar',
// "slide", "fade", "cube", "coverflow" or "flip"
effect: 'slide',
// Distance between slides in px.
spaceBetween: 30,
//
slidesPerView: 3,
//
centeredSlides: true,
//
slidesOffsetBefore: 0,
//
grabCursor: true,
})

Binary file not shown.
47 changes: 47 additions & 0 deletions Code/code/ML/SON/pipeline/img_video/trans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch



repo = "davidkim205/iris-7b"
model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype=torch.bfloat16, device_map='auto')
tokenizer = AutoTokenizer.from_pretrained(repo)

def generate(prompt):
encoding = tokenizer(
prompt,
return_tensors='pt',
return_token_type_ids=False
).to("cuda")
gen_tokens = model.generate(
**encoding,
max_new_tokens=2048,
temperature=1.0,
num_beams=5,
)
prompt_end_size = encoding.input_ids.shape[1]
result = tokenizer.decode(gen_tokens[0, prompt_end_size:])

return result


def translate_ko2en(text):
prompt = f"[INST] 다음 문장을 영어로 번역하세요.{text} [/INST]"
return generate(prompt)


def translate_en2ko(text):
prompt = f"[INST] 다음 문장을 한글로 번역하세요.{text} [/INST]"
return generate(prompt)


def main():
while True:
text = input('>')
en_text = translate_ko2en(text)
ko_text = translate_en2ko(en_text)
print('en_text', en_text)
print('ko_text', ko_text)

if __name__ == "__main__":
main()
68 changes: 68 additions & 0 deletions Code/code/ML/SON/pipeline/img_video/video.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import torch
from diffusers import I2VGenXLPipeline
from diffusers.utils import export_to_gif, load_image
from .trans import translate_ko2en
import langdetect
import random
from PIL import Image
import os


pipeline = I2VGenXLPipeline.from_pretrained("ali-vilab/i2vgen-xl", torch_dtype=torch.float16, variant="fp16")
pipeline.enable_model_cpu_offload()
generator = torch.manual_seed(0)


def vid_generate(recommended_img:str,user_prompt:str,steps,scale,user):
#recommend img is path
path = recommended_img
print(path)
random_number = int(random.random()*100)
prompt = user_prompt
orig_size = Image.open(recommended_img).size

if orig_size[1]<orig_size[0]:
orig_size2=(orig_size[1],orig_size[0])
image = load_image(path).convert("RGB")
image=image.resize(orig_size2)
else:
image = load_image(path).convert("RGB")

if langdetect.detect(prompt)=="ko":

prompt=translate_ko2en(prompt)
prompt=prompt.split(".")[0]
prompt=prompt.lower()


else:

prompt=prompt.lower()


negative_prompt = """Distorted, gray, discontinuous, Ugly,
blurry, low resolution, motionless,
static, disfigured, disconnected limbs,
Ugly faces, incomplete arms"""

frames = pipeline(
prompt = prompt,
image = image,
num_inference_steps=steps, #95
negative_prompt=negative_prompt,
guidance_scale=scale,
# 9.0 , 1.0
generator=generator
).frames[0]


name=path.split(".")[0]
if name.find("/")>-1:
name=name.split("/")[-2]


os.makedirs(f"{user}/gifs",exist_ok=True)
export_to_gif(frames, f"{user}/gifs/{prompt}__{name}__{random_number}.gif")
print("Gif Saved")

return f"{user}/gifs/{prompt}__{name}__{random_number}.gif"
Binary file not shown.

0 comments on commit adc2049

Please sign in to comment.