madanyc commited on
Commit
493729a
·
verified ·
1 Parent(s): ce18e8b

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .gitattributes +35 -35
  2. .gitignore +4 -0
  3. README.md +14 -14
  4. app.py +126 -51
  5. requirements.txt +3 -0
.gitattributes CHANGED
@@ -1,35 +1,35 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .env
README.md CHANGED
@@ -1,14 +1,14 @@
1
- ---
2
- title: Audiotranscribe
3
- emoji: 🏢
4
- colorFrom: red
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 6.12.0
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- short_description: Transcribe Audio and Create a Summary
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: Audiotranscribe
3
+ emoji: 🏢
4
+ colorFrom: red
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 6.12.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ short_description: Transcribe Audio and Create a Summary
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,51 +1,126 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- client = InferenceClient()
5
-
6
-
7
- def transcribe(audio):
8
- if audio is None:
9
- return "", ""
10
- text = client.automatic_speech_recognition(audio, model="openai/whisper-base")
11
- return text.text, ""
12
-
13
-
14
- def summarize(text):
15
- if not text or not text.strip():
16
- return "No text to summarize."
17
- if len(text.split()) < 30:
18
- return "Text is too short to summarize."
19
- result = client.summarization(text, model="facebook/bart-large-cnn")
20
- return result.summary_text
21
-
22
-
23
- with gr.Blocks(title="Audio Transcription & Summary") as demo:
24
- gr.Markdown("# 🎙️ Audio Transcription & Summary")
25
- gr.Markdown("Upload or record audio to transcribe it, then generate a summary.")
26
-
27
- with gr.Row():
28
- audio_input = gr.Audio(type="filepath", label="Upload or Record Audio")
29
-
30
- with gr.Row():
31
- transcribe_btn = gr.Button("Transcribe", variant="primary")
32
-
33
- transcription_output = gr.Textbox(label="Transcription", lines=10)
34
-
35
- with gr.Row():
36
- summarize_btn = gr.Button("Summarize", variant="secondary")
37
-
38
- summary_output = gr.Textbox(label="Summary", lines=5)
39
-
40
- transcribe_btn.click(
41
- fn=transcribe,
42
- inputs=audio_input,
43
- outputs=[transcription_output, summary_output],
44
- )
45
- summarize_btn.click(
46
- fn=summarize,
47
- inputs=transcription_output,
48
- outputs=summary_output,
49
- )
50
-
51
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import tempfile
4
+
5
+ import gradio as gr
6
+ from dotenv import load_dotenv
7
+ from huggingface_hub import InferenceClient
8
+
9
+ load_dotenv()
10
+
11
+ asr_client = InferenceClient(provider="hf-inference")
12
+ llm_client = InferenceClient()
13
+
14
+ LLM_MODEL = "meta-llama/Llama-3.3-70B-Instruct"
15
+
16
+
17
+ def transcribe_and_summarize(audio):
18
+ if audio is None:
19
+ return "", "", ""
20
+ try:
21
+ text = asr_client.automatic_speech_recognition(audio, model="openai/whisper-large-v3-turbo")
22
+ transcript = text.text
23
+ except Exception as e:
24
+ return "", f"Transcription failed: {e}", ""
25
+ if len(transcript.split()) < 30:
26
+ return transcript, "Text is too short to summarize.", ""
27
+ try:
28
+ result = llm_client.chat_completion(
29
+ model=LLM_MODEL,
30
+ messages=[
31
+ {"role": "system", "content": "You are a helpful assistant. Summarize the following text concisely."},
32
+ {"role": "user", "content": transcript},
33
+ ],
34
+ max_tokens=256,
35
+ )
36
+ return transcript, result.choices[0].message.content, ""
37
+ except Exception as e:
38
+ return transcript, f"Summarization failed: {e}", ""
39
+
40
+
41
+ def extract_action_items(text):
42
+ if not text or not text.strip():
43
+ return "No text to extract action items from."
44
+ try:
45
+ result = llm_client.chat_completion(
46
+ model=LLM_MODEL,
47
+ messages=[
48
+ {"role": "system", "content": (
49
+ "You are a helpful assistant. Extract all action items from the following text. "
50
+ "For each action item, identify the owner (if mentioned) and any deadline. "
51
+ "Format as a numbered list: '1. [Owner] - Action item (Deadline: ...)'. "
52
+ "If no action items are found, say 'No action items found.'"
53
+ )},
54
+ {"role": "user", "content": text},
55
+ ],
56
+ max_tokens=512,
57
+ )
58
+ return result.choices[0].message.content
59
+ except Exception as e:
60
+ return f"Action item extraction failed: {e}"
61
+
62
+
63
+ def _generate_filename(summary):
64
+ if summary and summary.strip() and not summary.startswith(("No text", "Text is too short", "Summarization failed")):
65
+ slug = re.sub(r"[^a-zA-Z0-9 ]", "", summary[:60]).strip()
66
+ slug = re.sub(r"\s+", "_", slug).lower()
67
+ if slug:
68
+ return f"{slug}.txt"
69
+ return "transcript_output.txt"
70
+
71
+
72
+ def download_txt(transcript, summary, action_items):
73
+ parts = []
74
+ if transcript and transcript.strip():
75
+ parts.append("=== TRANSCRIPTION ===\n" + transcript)
76
+ if summary and summary.strip():
77
+ parts.append("=== SUMMARY ===\n" + summary)
78
+ if action_items and action_items.strip():
79
+ parts.append("=== ACTION ITEMS ===\n" + action_items)
80
+ if not parts:
81
+ return None
82
+ content = "\n\n".join(parts)
83
+ filename = _generate_filename(summary)
84
+ path = os.path.join(tempfile.gettempdir(), filename)
85
+ with open(path, "w", encoding="utf-8") as f:
86
+ f.write(content)
87
+ return path
88
+
89
+
90
+ with gr.Blocks(title="Audio Transcription & Summary") as demo:
91
+ gr.Markdown("# 🎙️ Audio Transcription & Summary")
92
+ gr.Markdown("Upload an audio file or record from your microphone, then transcribe, summarize, and extract action items.")
93
+
94
+ with gr.Row():
95
+ audio_input = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Upload or Record Audio")
96
+
97
+ transcribe_summarize_btn = gr.Button("Transcribe & Summarize", variant="primary")
98
+
99
+ transcription_output = gr.Textbox(label="Transcription", lines=10)
100
+ summary_output = gr.Textbox(label="Summary", lines=5)
101
+
102
+ with gr.Row():
103
+ action_btn = gr.Button("Extract Action Items", variant="secondary")
104
+
105
+ action_output = gr.Textbox(label="Action Items", lines=5)
106
+
107
+ download_file = gr.File(label="Download", interactive=False)
108
+ download_btn = gr.Button("Download as .txt")
109
+
110
+ transcribe_summarize_btn.click(
111
+ fn=transcribe_and_summarize,
112
+ inputs=audio_input,
113
+ outputs=[transcription_output, summary_output, action_output],
114
+ )
115
+ action_btn.click(
116
+ fn=extract_action_items,
117
+ inputs=transcription_output,
118
+ outputs=action_output,
119
+ )
120
+ download_btn.click(
121
+ fn=download_txt,
122
+ inputs=[transcription_output, summary_output, action_output],
123
+ outputs=download_file,
124
+ )
125
+
126
+ demo.launch()
requirements.txt CHANGED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=4.0.0
2
+ huggingface_hub>=0.20.0
3
+ python-dotenv>=1.0.0