theahmedjaafari commited on
Commit
43c2663
1 Parent(s): 8253380

initial commit

Browse files
Files changed (3) hide show
  1. README copy.md +12 -0
  2. app.py +74 -0
  3. requirements.txt +2 -0
README copy.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Transcription
3
+ emoji: 📈
4
+ colorFrom: red
5
+ colorTo: yellow
6
+ sdk: gradio
7
+ sdk_version: 4.37.2
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+ import time
5
+
6
+ def upload_audio(file_path, progress=gr.Progress()):
7
+ url = f'{os.getenv("VOCHAI_URL")}/upload'
8
+ headers = {
9
+ 'accept': 'application/json',
10
+ 'Authorization': f'Bearer {os.getenv("VOCHAI_TOKEN")}',
11
+ }
12
+ with open(file_path, 'rb') as file:
13
+ files = {
14
+ 'file': (os.path.basename(file_path), file, 'audio/*')
15
+ }
16
+ progress(0, desc="Uploading audio...")
17
+ response = requests.post(url, headers=headers, files=files)
18
+ if response.status_code == 200:
19
+ progress(0.5, desc="Upload complete")
20
+ return response.json()
21
+ else:
22
+ print("Error:", response.status_code, response.text)
23
+ return None
24
+
25
+ def process_audio(audio_uri, progress=gr.Progress()):
26
+ url = f'{os.getenv("VOCHAI_URL")}/process?audio_uri={audio_uri}'
27
+ headers = {
28
+ 'accept': 'application/json',
29
+ 'Authorization': f'Bearer {os.getenv("VOCHAI_TOKEN")}',
30
+ }
31
+ progress(0.5, desc="Processing audio...")
32
+ response = requests.post(url, headers=headers)
33
+ if response.status_code == 200:
34
+ progress(1.0, desc="Processing complete")
35
+ return response.json()
36
+ else:
37
+ print("Error:", response.status_code, response.text)
38
+ return None
39
+
40
+ def upload_and_process_audio(audio_path, progress=gr.Progress()):
41
+ gr.Info("Uploading and processing audio. This may take a moment...")
42
+
43
+ # Upload the audio file
44
+ upload_result = upload_audio(audio_path, progress)
45
+ if not upload_result:
46
+ gr.Error("Upload failed")
47
+ return "Upload failed", "Upload failed"
48
+
49
+ audio_uri = upload_result.get('uri')
50
+
51
+ # Process the audio
52
+ process_result = process_audio(audio_uri, progress)
53
+ if not process_result:
54
+ gr.Error("Processing failed")
55
+ return "Processing failed", "Processing failed"
56
+
57
+ gr.Info("Audio processing completed successfully!")
58
+ # Return the transcript and topic
59
+ return process_result.get("topic", "No topic detected"), process_result.get("transcript", "No transcript available")
60
+
61
+ # Create the Gradio interface
62
+ iface = gr.Interface(
63
+ fn=upload_and_process_audio,
64
+ inputs=gr.Audio(type="filepath", label="Upload Audio File"),
65
+ outputs=[
66
+ gr.Textbox(label="Topic", rtl=True),
67
+ gr.Textbox(label="Transcript", rtl=True)
68
+ ],
69
+ title="Audio Transcription and Topic Detection",
70
+ description="Upload an audio file to get its transcript and detected topic.",
71
+ )
72
+
73
+ # Launch the interface
74
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ requests