seawolf2357 commited on
Commit
ba5f8a7
ยท
verified ยท
1 Parent(s): 0a6664d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -5,21 +5,21 @@ from gradio_client import Client # ๊ฐ€์ •: gradio_client ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์‚ฌ
5
  # ์ด๋ฏธ์ง€ ์ธ์‹ ํŒŒ์ดํ”„๋ผ์ธ ๋กœ๋“œ
6
  image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
- def generate_music(image_classification_result):
9
- # ์Œ์•… ์ƒ์„ฑ API ํ˜ธ์ถœ
10
  client = Client("https://haoheliu-audioldm2-text2audio-text2music.hf.space/")
11
- "The rnb beat of 85BPM drums. playing Violin."
12
- "Low quality."
13
- 5, # ์Œ์•…์˜ ๊ธธ์ด (์ดˆ), ํ‚ค์›Œ๋“œ ์ธ์ž๋กœ ๋ณ€๊ฒฝ
14
- 0, # ๊ฐ€์ด๋˜์Šค ์Šค์ผ€์ผ, ํ‚ค์›Œ๋“œ ์ธ์ž๋กœ ๋ณ€๊ฒฝ
15
- 5, # ์‹œ๋“œ ๊ฐ’, ํ‚ค์›Œ๋“œ ์ธ์ž๋กœ ๋ณ€๊ฒฝ
16
- 1, # ์ƒ์„ฑํ•  waveform์˜ ์ˆ˜, ํ‚ค์›Œ๋“œ ์ธ์ž๋กœ ๋ณ€๊ฒฝ
17
- fn_index=1 # ํ•จ์ˆ˜ ์ธ๋ฑ์Šค, ์ด๋ฏธ ํ‚ค์›Œ๋“œ ์ธ์ž๋กœ ๋˜์–ด ์žˆ์Œ
 
 
18
  )
19
-
20
- # ์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜ ๊ฒฐ๊ณผ๋ฅผ ํฌํ•จํ•œ ์ „์ฒด ํ”„๋กฌํ”„ํŠธ ์ƒ์„ฑ
21
- full_prompt = f"{base_prompt} Inspired by: {image_classification_result}."
22
- # API ํ˜ธ์ถœ ๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ
23
  return result
24
 
25
  def generate_voice(prompt):
@@ -43,7 +43,7 @@ def classify_and_generate_voice(uploaded_image):
43
  # ์Œ์„ฑ ์ƒ์„ฑ
44
  voice_result = generate_voice(top_prediction)
45
  # ์Œ์•… ์ƒ์„ฑ
46
- music_result = generate_music("Generate music for: " + top_prediction)
47
 
48
  # ๋ฐ˜ํ™˜๋œ ์Œ์„ฑ ๋ฐ ์Œ์•… ๊ฒฐ๊ณผ๋ฅผ Gradio ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์ „๋‹ฌ
49
  # ์˜ˆ: voice_result['url'] ๋˜๋Š” voice_result['audio_data'] ๋“ฑ
 
5
  # ์ด๋ฏธ์ง€ ์ธ์‹ ํŒŒ์ดํ”„๋ผ์ธ ๋กœ๋“œ
6
  image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
+ def generate_music(prompt):
9
+ # audioldm API ์‚ฌ์šฉํ•˜์—ฌ ์Œ์•… ์ƒ์„ฑ API ํ˜ธ์ถœ
10
  client = Client("https://haoheliu-audioldm2-text2audio-text2music.hf.space/")
11
+ seed = random.randint(0, MAX_SEED)
12
+ result = client.predict(
13
+ prompt, # str in 'Input text' Textbox component
14
+ "Low quality.", # str in 'Negative prompt' Textbox component
15
+ 5, # int | float (numeric value between 5 and 15) in 'Duration (seconds)' Slider component
16
+ 6.5, # int | float (numeric value between 0 and 7) in 'Guidance scale' Slider component
17
+ seed, # int | float in 'Seed' Number component
18
+ 3, # int | float (numeric value between 1 and 5) in 'Number waveforms to generate' Slider component
19
+ fn_index=1
20
  )
21
+ #print(result)
22
+ #audio_result = extract_audio(result)
 
 
23
  return result
24
 
25
  def generate_voice(prompt):
 
43
  # ์Œ์„ฑ ์ƒ์„ฑ
44
  voice_result = generate_voice(top_prediction)
45
  # ์Œ์•… ์ƒ์„ฑ
46
+ music_result = generate_music("Generate music for: " + top_prediction + prompt)
47
 
48
  # ๋ฐ˜ํ™˜๋œ ์Œ์„ฑ ๋ฐ ์Œ์•… ๊ฒฐ๊ณผ๋ฅผ Gradio ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์ „๋‹ฌ
49
  # ์˜ˆ: voice_result['url'] ๋˜๋Š” voice_result['audio_data'] ๋“ฑ