openfree commited on
Commit
67a946c
Β·
verified Β·
1 Parent(s): 2524c67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -24,7 +24,7 @@ pipe = pipeline(
24
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
25
 
26
  @spaces.GPU
27
- def transcribe_summarize_and_blog(inputs, task):
28
  if inputs is None:
29
  raise gr.Error("μ˜€λ””μ˜€ 파일이 μ œμΆœλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€! μš”μ²­μ„ μ œμΆœν•˜κΈ° 전에 μ˜€λ””μ˜€ νŒŒμΌμ„ μ—…λ‘œλ“œν•˜κ±°λ‚˜ λ…ΉμŒν•΄ μ£Όμ„Έμš”.")
30
 
@@ -38,25 +38,11 @@ def transcribe_summarize_and_blog(inputs, task):
38
  except Exception as e:
39
  summary_text = f"μš”μ•½ 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}"
40
 
41
- # λΈ”λ‘œκ·Έ ν¬μŠ€νŒ… 생성 μš”μ²­
42
- try:
43
- blog_post = hf_client.text_generation(
44
- prompt=f"λ‹€μŒ λ‚΄μš©μ„ 기반으둜 λΈ”λ‘œκ·Έ ν¬μŠ€νŒ…μ„ μž‘μ„±ν•΄ μ£Όμ„Έμš”:\n{text}",
45
- temperature=0.7
46
- )
47
- blog_post_text = blog_post if isinstance(blog_post, str) else "λΈ”λ‘œκ·Έ ν¬μŠ€νŒ…μ„ 생성할 수 μ—†μŠ΅λ‹ˆλ‹€."
48
- except Exception as e:
49
- blog_post_text = f"λΈ”λ‘œκ·Έ κΈ€ 생성 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}"
50
-
51
  return {
52
  "transcribed_text": text,
53
- "summary": summary_text,
54
- "blog_post": blog_post_text
55
  }
56
 
57
-
58
-
59
-
60
  css = """
61
  footer {
62
  visibility: hidden;
@@ -64,24 +50,24 @@ footer {
64
  """
65
 
66
  file_transcribe = gr.Interface(
67
- fn=transcribe_summarize_and_blog,
68
  inputs=[
69
  gr.Audio(sources="upload", type="filepath", label="μ˜€λ””μ˜€ 파일"),
70
  gr.Radio(["transcribe", "translate"], label="μž‘μ—…", value="transcribe"),
71
  ],
72
- outputs=["text", "text", "text"], # λ³€ν™˜λœ ν…μŠ€νŠΈ, μš”μ•½, λΈ”λ‘œκ·Έ κΈ€ 좜λ ₯
73
- title="λ°›μ•„μ“°κΈ° AI: μŒμ„±μ„ ν…μŠ€νŠΈ λ³€ν™˜, μš”μ•½ 및 λΈ”λ‘œκ·Έ ν¬μŠ€νŒ… μžλ™ 생성",
74
  flagging_mode="never",
75
  )
76
 
77
  mf_transcribe = gr.Interface(css=css,
78
- fn=transcribe_summarize_and_blog,
79
  inputs=[
80
  gr.Audio(sources="microphone", type="filepath"),
81
  gr.Radio(["transcribe", "translate"], label="μž‘μ—…", value="transcribe"),
82
  ],
83
- outputs=["text", "text", "text"], # λ³€ν™˜λœ ν…μŠ€νŠΈ, μš”μ•½, λΈ”λ‘œκ·Έ κΈ€ 좜λ ₯
84
- title="λ°›μ•„μ“°κΈ° AI: μŒμ„±μ„ ν…μŠ€νŠΈ λ³€ν™˜, μš”μ•½ 및 λΈ”λ‘œκ·Έ ν¬μŠ€νŒ… μžλ™ 생성",
85
  flagging_mode="never",
86
  )
87
 
@@ -93,3 +79,4 @@ with demo:
93
  gr.TabbedInterface([file_transcribe, mf_transcribe], ["μ˜€λ””μ˜€ 파일", "마이크"])
94
 
95
  demo.queue().launch(ssr_mode=False)
 
 
24
  hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024", token=os.getenv("HF_TOKEN"))
25
 
26
  @spaces.GPU
27
+ def transcribe_summarize(inputs, task):
28
  if inputs is None:
29
  raise gr.Error("μ˜€λ””μ˜€ 파일이 μ œμΆœλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€! μš”μ²­μ„ μ œμΆœν•˜κΈ° 전에 μ˜€λ””μ˜€ νŒŒμΌμ„ μ—…λ‘œλ“œν•˜κ±°λ‚˜ λ…ΉμŒν•΄ μ£Όμ„Έμš”.")
30
 
 
38
  except Exception as e:
39
  summary_text = f"μš”μ•½ 쀑 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}"
40
 
 
 
 
 
 
 
 
 
 
 
41
  return {
42
  "transcribed_text": text,
43
+ "summary": summary_text
 
44
  }
45
 
 
 
 
46
  css = """
47
  footer {
48
  visibility: hidden;
 
50
  """
51
 
52
  file_transcribe = gr.Interface(
53
+ fn=transcribe_summarize,
54
  inputs=[
55
  gr.Audio(sources="upload", type="filepath", label="μ˜€λ””μ˜€ 파일"),
56
  gr.Radio(["transcribe", "translate"], label="μž‘μ—…", value="transcribe"),
57
  ],
58
+ outputs=["text", "text"], # λ³€ν™˜λœ ν…μŠ€νŠΈ, μš”μ•½ 좜λ ₯
59
+ title="λ°›μ•„μ“°κΈ° AI: μŒμ„±μ„ ν…μŠ€νŠΈ λ³€ν™˜, μš”μ•½ μžλ™ 생성",
60
  flagging_mode="never",
61
  )
62
 
63
  mf_transcribe = gr.Interface(css=css,
64
+ fn=transcribe_summarize,
65
  inputs=[
66
  gr.Audio(sources="microphone", type="filepath"),
67
  gr.Radio(["transcribe", "translate"], label="μž‘μ—…", value="transcribe"),
68
  ],
69
+ outputs=["text", "text"], # λ³€ν™˜λœ ν…μŠ€νŠΈ, μš”μ•½ 좜λ ₯
70
+ title="λ°›μ•„μ“°κΈ° AI: μŒμ„±μ„ ν…μŠ€νŠΈ λ³€ν™˜, μš”μ•½ μžλ™ 생성",
71
  flagging_mode="never",
72
  )
73
 
 
79
  gr.TabbedInterface([file_transcribe, mf_transcribe], ["μ˜€λ””μ˜€ 파일", "마이크"])
80
 
81
  demo.queue().launch(ssr_mode=False)
82
+