seawolf2357 commited on
Commit
e57e37e
Β·
verified Β·
1 Parent(s): 1defd08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -24
app.py CHANGED
@@ -1,49 +1,32 @@
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()
44
-
45
- examples = [['./dog.jpg'],]
46
- demo = gr.Interface(fn=process,inputs="image", outputs="image", examples=examples, title=title, description=description)
47
-
48
  if __name__ == "__main__":
49
- demo.launch(share=False)
 
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)