openfree commited on
Commit
01e0630
ยท
verified ยท
1 Parent(s): 22d9a40

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -216
app.py DELETED
@@ -1,216 +0,0 @@
1
- import spaces
2
- import torch
3
- import gradio as gr
4
- from transformers import pipeline
5
- from huggingface_hub import InferenceClient
6
- import os
7
- from datetime import datetime
8
-
9
- MODEL_NAME = "openai/whisper-large-v3-turbo"
10
- BATCH_SIZE = 8
11
- FILE_LIMIT_MB = 1000
12
-
13
- device = 0 if torch.cuda.is_available() else "cpu"
14
-
15
- # Whisper ํŒŒ์ดํ”„๋ผ์ธ ์ดˆ๊ธฐํ™”
16
- pipe = pipeline(
17
- task="automatic-speech-recognition",
18
- model=MODEL_NAME,
19
- chunk_length_s=30,
20
- device=device,
21
- )
22
-
23
- # Hugging Face ์ถ”๋ก  ํด๋ผ์ด์–ธํŠธ ์„ค์ •
24
- hf_client = InferenceClient(
25
- "CohereForAI/c4ai-command-r-plus-08-2024",
26
- token=os.getenv("HF_TOKEN")
27
- )
28
-
29
- def get_word_count(text):
30
- """ํ…์ŠคํŠธ์˜ ๋‹จ์–ด ์ˆ˜ ๊ณ„์‚ฐ"""
31
- if not text:
32
- return 0
33
- return len(text.split())
34
-
35
- def format_duration(seconds):
36
- """์ดˆ ๋‹จ์œ„ ์‹œ๊ฐ„์„ mm:ss ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜"""
37
- try:
38
- minutes = int(seconds // 60)
39
- seconds = int(seconds % 60)
40
- return f"{minutes:02d}:{seconds:02d}"
41
- except:
42
- return "00:00"
43
-
44
- @spaces.GPU
45
- def transcribe_summarize(audio_input, task):
46
- if audio_input is None:
47
- raise gr.Error("์˜ค๋””์˜ค ํŒŒ์ผ์ด ์ œ์ถœ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค!")
48
-
49
- try:
50
- # ์Œ์„ฑ์„ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜
51
- result = pipe(
52
- audio_input,
53
- batch_size=BATCH_SIZE,
54
- generate_kwargs={"task": task},
55
- return_timestamps=True
56
- )
57
- transcribed_text = result["text"]
58
-
59
- # ๊ธฐ๋ณธ ๋ถ„์„ ์ •๋ณด
60
- word_count = get_word_count(transcribed_text)
61
- duration = format_duration(result.get("duration", 0))
62
-
63
- # ํ…์ŠคํŠธ ์š”์•ฝ
64
- try:
65
- prompt = (
66
- "๋‹ค์Œ ํ…์ŠคํŠธ๋ฅผ ํ•œ๊ตญ์–ด๋กœ ๊ฐ„๋‹จํžˆ ์š”์•ฝํ•ด์ฃผ์„ธ์š”:\n\n"
67
- f"ํ…์ŠคํŠธ: {transcribed_text}\n"
68
- "์š”์•ฝ:"
69
- )
70
-
71
- response = hf_client.text_generation(
72
- prompt=prompt,
73
- max_new_tokens=500,
74
- temperature=0.3,
75
- top_p=0.9,
76
- repetition_penalty=1.2
77
- )
78
-
79
- summary_text = str(response)
80
- if "์š”์•ฝ:" in summary_text:
81
- summary_text = summary_text.split("์š”์•ฝ:")[1].strip()
82
-
83
- except Exception as e:
84
- print(f"์š”์•ฝ ์ƒ์„ฑ ์ค‘ ์˜ค๋ฅ˜: {str(e)}")
85
- summary_text = "์š”์•ฝ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
86
-
87
- # ๋ถ„์„ ์ •๋ณด ํฌ๋งทํŒ…
88
- stats = f"""
89
- ๐Ÿ“Š ๋ถ„์„ ์ •๋ณด:
90
- - ๋‹จ์–ด ์ˆ˜: {word_count}๊ฐœ
91
- - ์Œ์„ฑ ๊ธธ์ด: {duration}
92
- - ์ƒ์„ฑ ์‹œ๊ฐ„: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}
93
- """
94
-
95
- return [transcribed_text, summary_text, stats]
96
-
97
- except Exception as e:
98
- error_msg = f"์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}"
99
- return ["", error_msg, ""]
100
-
101
- # CSS ์Šคํƒ€์ผ
102
- css = """
103
- footer { visibility: hidden; }
104
- .gradio-container {
105
- max-width: 1000px;
106
- margin: auto;
107
- padding: 20px;
108
- }
109
- .output-stats {
110
- background-color: #f5f5f5;
111
- padding: 10px;
112
- border-radius: 5px;
113
- font-family: monospace;
114
- }
115
- """
116
-
117
- # ํŒŒ์ผ ์—…๋กœ๋“œ ์ธํ„ฐํŽ˜์ด์Šค
118
- file_transcribe = gr.Interface(
119
- fn=transcribe_summarize,
120
- inputs=[
121
- gr.Audio(
122
- sources="upload",
123
- type="filepath",
124
- label="์˜ค๋””์˜ค ํŒŒ์ผ"
125
- ),
126
- gr.Radio(
127
- choices=["transcribe", "translate"],
128
- label="์ž‘์—… ์„ ํƒ",
129
- value="transcribe"
130
- )
131
- ],
132
- outputs=[
133
- gr.Textbox(
134
- label="๋ณ€ํ™˜๋œ ํ…์ŠคํŠธ",
135
- lines=5,
136
- placeholder="์Œ์„ฑ์ด ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜๋˜์–ด ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค..."
137
- ),
138
- gr.Textbox(
139
- label="์š”์•ฝ",
140
- lines=3,
141
- placeholder="ํ…์ŠคํŠธ ์š”์•ฝ์ด ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค..."
142
- ),
143
- gr.Textbox(
144
- label="๋ถ„์„ ์ •๋ณด",
145
- lines=4,
146
- placeholder="๋ถ„์„ ์ •๋ณด๊ฐ€ ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค..."
147
- )
148
- ],
149
- title="๐ŸŽค ๋ฐ›์•„์“ฐ๊ธฐ AI",
150
- description="""
151
- ์Œ์„ฑ ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ์ง์ ‘ ๋…น์Œํ•˜์—ฌ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ์š”์•ฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
152
-
153
- ์‚ฌ์šฉ ๋ฐฉ๋ฒ•:
154
- 1. ์˜ค๋””์˜ค ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๊ฑฐ๋‚˜ ๋งˆ์ดํฌ๋กœ ๋…น์Œํ•˜์„ธ์š”
155
- 2. ์ž‘์—… ์œ ํ˜•์„ ์„ ํƒํ•˜์„ธ์š” (๋ณ€ํ™˜ ๋˜๋Š” ๋ฒˆ์—ญ)
156
- 3. ๋ณ€ํ™˜ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š”
157
- """,
158
- article="developed by Claude",
159
- examples=[],
160
- cache_examples=False,
161
- flagging_mode="never"
162
- )
163
-
164
- # ๋งˆ์ดํฌ ๋…น์Œ ์ธํ„ฐํŽ˜์ด์Šค
165
- mic_transcribe = gr.Interface(
166
- fn=transcribe_summarize,
167
- inputs=[
168
- gr.Audio(
169
- sources="microphone",
170
- type="filepath",
171
- label="๋งˆ์ดํฌ ๋…น์Œ"
172
- ),
173
- gr.Radio(
174
- choices=["transcribe", "translate"],
175
- label="์ž‘์—… ์„ ํƒ",
176
- value="transcribe"
177
- )
178
- ],
179
- outputs=[
180
- gr.Textbox(
181
- label="๋ณ€ํ™˜๋œ ํ…์ŠคํŠธ",
182
- lines=5,
183
- placeholder="์Œ์„ฑ์ด ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜๋˜์–ด ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค..."
184
- ),
185
- gr.Textbox(
186
- label="์š”์•ฝ",
187
- lines=3,
188
- placeholder="ํ…์ŠคํŠธ ์š”์•ฝ์ด ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค..."
189
- ),
190
- gr.Textbox(
191
- label="๋ถ„์„ ์ •๋ณด",
192
- lines=4,
193
- placeholder="๋ถ„์„ ์ •๋ณด๊ฐ€ ์—ฌ๊ธฐ์— ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค..."
194
- )
195
- ],
196
- title="๐ŸŽค ๋ฐ›์•„์“ฐ๊ธฐ AI",
197
- description="๋งˆ์ดํฌ๋กœ ์Œ์„ฑ์„ ๋…น์Œํ•˜์—ฌ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•˜๊ณ  ์š”์•ฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.",
198
- flagging_mode="never",
199
- css=css
200
- )
201
-
202
- # ๋ฉ”์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜
203
- demo = gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css)
204
- with demo:
205
- gr.TabbedInterface(
206
- [file_transcribe, mic_transcribe],
207
- ["์˜ค๋””์˜ค ํŒŒ์ผ", "๋งˆ์ดํฌ ๋…น์Œ"]
208
- )
209
-
210
- # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
211
- demo.queue().launch(
212
- share=False,
213
- debug=True,
214
- show_error=True,
215
- ssr_mode=False
216
- )