Update app.py
Browse files
app.py
CHANGED
@@ -27,9 +27,8 @@ hf_client = InferenceClient(
|
|
27 |
|
28 |
@spaces.GPU
|
29 |
def transcribe_summarize(audio_input, task):
|
30 |
-
# μ
λ ₯ κ²μ¦
|
31 |
if audio_input is None:
|
32 |
-
raise gr.Error("μ€λμ€ νμΌμ΄ μ μΆλμ§ μμμ΅λλ€!
|
33 |
|
34 |
# μμ±μ ν
μ€νΈλ‘ λ³ν
|
35 |
result = pipe(
|
@@ -40,14 +39,36 @@ def transcribe_summarize(audio_input, task):
|
|
40 |
)
|
41 |
transcribed_text = result["text"]
|
42 |
|
43 |
-
# ν
μ€νΈ μμ½
|
44 |
try:
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
except Exception as e:
|
48 |
-
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
# κ²°κ³Όλ₯Ό 리μ€νΈλ‘ λ°ν
|
51 |
return [transcribed_text, summary_text]
|
52 |
|
53 |
# CSS μ€νμΌ
|
@@ -67,8 +88,8 @@ file_transcribe = gr.Interface(
|
|
67 |
),
|
68 |
],
|
69 |
outputs=[
|
70 |
-
gr.Textbox(label="λ³νλ ν
μ€νΈ"),
|
71 |
-
gr.Textbox(label="μμ½")
|
72 |
],
|
73 |
title="λ°μμ°κΈ° AI: μμ±μ ν
μ€νΈλ‘ λ³ννκ³ μμ½νκΈ°",
|
74 |
flagging_mode="never"
|
@@ -86,8 +107,8 @@ mic_transcribe = gr.Interface(
|
|
86 |
),
|
87 |
],
|
88 |
outputs=[
|
89 |
-
gr.Textbox(label="λ³νλ ν
μ€νΈ"),
|
90 |
-
gr.Textbox(label="μμ½")
|
91 |
],
|
92 |
title="λ°μμ°κΈ° AI: μμ±μ ν
μ€νΈλ‘ λ³ννκ³ μμ½νκΈ°",
|
93 |
flagging_mode="never",
|
|
|
27 |
|
28 |
@spaces.GPU
|
29 |
def transcribe_summarize(audio_input, task):
|
|
|
30 |
if audio_input is None:
|
31 |
+
raise gr.Error("μ€λμ€ νμΌμ΄ μ μΆλμ§ μμμ΅λλ€!")
|
32 |
|
33 |
# μμ±μ ν
μ€νΈλ‘ λ³ν
|
34 |
result = pipe(
|
|
|
39 |
)
|
40 |
transcribed_text = result["text"]
|
41 |
|
42 |
+
# ν
μ€νΈ μμ½ (μμ λ λΆλΆ)
|
43 |
try:
|
44 |
+
# μμ½ API νΈμΆ νλΌλ―Έν° μ€μ
|
45 |
+
summary_params = {
|
46 |
+
"text": transcribed_text,
|
47 |
+
"max_length": 150,
|
48 |
+
"min_length": 30,
|
49 |
+
"do_sample": False
|
50 |
+
}
|
51 |
+
|
52 |
+
# API νΈμΆ
|
53 |
+
response = hf_client.text_generation(
|
54 |
+
prompt=f"Please summarize the following text:\n{transcribed_text}\n\nSummary:",
|
55 |
+
max_new_tokens=150,
|
56 |
+
temperature=0.3,
|
57 |
+
repetition_penalty=1.2
|
58 |
+
)
|
59 |
+
|
60 |
+
summary_text = response[0]["generated_text"] if response else "μμ½μ μμ±ν μ μμ΅λλ€."
|
61 |
+
|
62 |
+
# ν둬ννΈ λΆλΆ μ κ±°
|
63 |
+
summary_text = summary_text.split("Summary:")[1].strip() if "Summary:" in summary_text else summary_text
|
64 |
+
|
65 |
except Exception as e:
|
66 |
+
print(f"μμ½ μμ± μ€ μ€λ₯ λ°μ: {str(e)}") # λλ²κΉ
μ μν λ‘κ·Έ
|
67 |
+
summary_text = f"μμ½ μμ± μ€ μ€λ₯κ° λ°μνμ΅λλ€: {str(e)}"
|
68 |
+
|
69 |
+
print(f"λ³νλ ν
μ€νΈ: {transcribed_text}") # λλ²κΉ
μ μν λ‘κ·Έ
|
70 |
+
print(f"μμ±λ μμ½: {summary_text}") # λλ²κΉ
μ μν λ‘κ·Έ
|
71 |
|
|
|
72 |
return [transcribed_text, summary_text]
|
73 |
|
74 |
# CSS μ€νμΌ
|
|
|
88 |
),
|
89 |
],
|
90 |
outputs=[
|
91 |
+
gr.Textbox(label="λ³νλ ν
μ€νΈ", lines=5),
|
92 |
+
gr.Textbox(label="μμ½", lines=3)
|
93 |
],
|
94 |
title="λ°μμ°κΈ° AI: μμ±μ ν
μ€νΈλ‘ λ³ννκ³ μμ½νκΈ°",
|
95 |
flagging_mode="never"
|
|
|
107 |
),
|
108 |
],
|
109 |
outputs=[
|
110 |
+
gr.Textbox(label="λ³νλ ν
μ€νΈ", lines=5),
|
111 |
+
gr.Textbox(label="μμ½", lines=3)
|
112 |
],
|
113 |
title="λ°μμ°κΈ° AI: μμ±μ ν
μ€νΈλ‘ λ³ννκ³ μμ½νκΈ°",
|
114 |
flagging_mode="never",
|