seawolf2357 commited on
Commit
a6d7b81
ยท
verified ยท
1 Parent(s): e57e37e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -8
app.py CHANGED
@@ -1,32 +1,43 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- # gradio_client ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ ๊ฐ€์ •
4
 
5
  # ์ด๋ฏธ์ง€ ์ธ์‹ ํŒŒ์ดํ”„๋ผ์ธ ๋กœ๋“œ
6
  image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
  def generate_voice(prompt):
9
- # Tango API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Œ์„ฑ ์ƒ์„ฑ (๊ฐ€์ •)
10
- return "https://example.com/generated_voice.mp3" # ์˜ˆ์‹œ ์Œ์„ฑ ํŒŒ์ผ URL ๋ฐ˜ํ™˜
 
 
 
 
 
 
 
 
 
11
 
12
  def classify_and_generate_voice(uploaded_image):
13
  # ์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜
14
  predictions = image_model(uploaded_image)
15
- top_prediction = predictions[0]['label']
 
16
  # ์Œ์„ฑ ์ƒ์„ฑ
17
  voice_result = generate_voice(top_prediction)
 
 
 
18
  return top_prediction, voice_result
19
 
20
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ ๋ฐ ์˜ˆ์‹œ ์ด๋ฏธ์ง€ ์„ค์ •
21
  iface = gr.Interface(
22
  fn=classify_and_generate_voice,
23
  inputs=gr.Image(type="pil"),
24
  outputs=[gr.Label(), gr.Audio()],
25
- examples=[["dog.jpg"]], # ์˜ˆ์‹œ ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ์ถ”๊ฐ€
26
  title="์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜ ๋ฐ ์Œ์„ฑ ์ƒ์„ฑ",
27
  description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด, ์‚ฌ๋ฌผ์„ ์ธ์‹ํ•˜๊ณ  ํ•ด๋‹นํ•˜๋Š” ์Œ์„ฑ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค."
28
  )
29
 
30
  # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
31
- if __name__ == "__main__":
32
- iface.launch(share=True)
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from gradio_client import Client # ๊ฐ€์ •: gradio_client ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.
4
 
5
  # ์ด๋ฏธ์ง€ ์ธ์‹ ํŒŒ์ดํ”„๋ผ์ธ ๋กœ๋“œ
6
  image_model = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
  def generate_voice(prompt):
9
+ # Tango API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์Œ์„ฑ ์ƒ์„ฑ
10
+ client = Client("https://declare-lab-tango.hf.space/")
11
+ result = client.predict(
12
+ prompt, # ์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜ ๊ฒฐ๊ณผ๋ฅผ ํ”„๋กฌํ”„ํŠธ๋กœ ์‚ฌ์šฉ
13
+ 100, # Steps
14
+ 1, # Guidance Scale
15
+ api_name="/predict" # API ์—”๋“œํฌ์ธํŠธ ๊ฒฝ๋กœ
16
+ )
17
+ # Tango API ํ˜ธ์ถœ ๊ฒฐ๊ณผ ์ฒ˜๋ฆฌ
18
+ # ์˜ˆ: result์—์„œ ์Œ์„ฑ ํŒŒ์ผ URL ๋˜๋Š” ๋ฐ์ดํ„ฐ ์ถ”์ถœ
19
+ return result
20
 
21
  def classify_and_generate_voice(uploaded_image):
22
  # ์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜
23
  predictions = image_model(uploaded_image)
24
+ top_prediction = predictions[0]['label'] # ๊ฐ€์žฅ ํ™•๋ฅ ์ด ๋†’์€ ๋ถ„๋ฅ˜ ๊ฒฐ๊ณผ
25
+
26
  # ์Œ์„ฑ ์ƒ์„ฑ
27
  voice_result = generate_voice(top_prediction)
28
+
29
+ # ๋ฐ˜ํ™˜๋œ ์Œ์„ฑ ๊ฒฐ๊ณผ๋ฅผ Gradio ์ธํ„ฐํŽ˜์ด์Šค๋กœ ์ „๋‹ฌ
30
+ # ์˜ˆ: voice_result['url'] ๋˜๋Š” voice_result['audio_data'] ๋“ฑ
31
  return top_prediction, voice_result
32
 
33
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
34
  iface = gr.Interface(
35
  fn=classify_and_generate_voice,
36
  inputs=gr.Image(type="pil"),
37
  outputs=[gr.Label(), gr.Audio()],
 
38
  title="์ด๋ฏธ์ง€ ๋ถ„๋ฅ˜ ๋ฐ ์Œ์„ฑ ์ƒ์„ฑ",
39
  description="์ด๋ฏธ์ง€๋ฅผ ์—…๋กœ๋“œํ•˜๋ฉด, ์‚ฌ๋ฌผ์„ ์ธ์‹ํ•˜๊ณ  ํ•ด๋‹นํ•˜๋Š” ์Œ์„ฑ์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค."
40
  )
41
 
42
  # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
43
+ iface.launch()