Spaces:
Runtime error
Runtime error
Pranjal12345
commited on
Commit
•
5606356
1
Parent(s):
b7f00c1
Update main.py
Browse files
main.py
CHANGED
@@ -1,204 +1,3 @@
|
|
1 |
-
# # #uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
2 |
-
|
3 |
-
|
4 |
-
# # # from fastapi import FastAPI
|
5 |
-
# # # from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
6 |
-
# # # import librosa
|
7 |
-
# # # import uvicorn
|
8 |
-
|
9 |
-
# # # app = FastAPI()
|
10 |
-
|
11 |
-
# # # processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
12 |
-
# # # model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
|
13 |
-
# # # model.config.forced_decoder_ids = None
|
14 |
-
|
15 |
-
# # # audio_file_path = "output.mp3"
|
16 |
-
|
17 |
-
# # # audio_data, _ = librosa.load(audio_file_path, sr=16000)
|
18 |
-
|
19 |
-
# # # @app.get("/")
|
20 |
-
# # # def transcribe_audio():
|
21 |
-
# # # input_features = processor(audio_data.tolist(), return_tensors="pt").input_features
|
22 |
-
|
23 |
-
# # # predicted_ids = model.generate(input_features)
|
24 |
-
# # # transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
25 |
-
|
26 |
-
# # # return {"transcription": transcription[0]}
|
27 |
-
|
28 |
-
|
29 |
-
# # # if __name__ == "__main__":
|
30 |
-
# # # import uvicorn
|
31 |
-
# # # uvicorn.run(app, host="0.0.0.0", port=8000)
|
32 |
-
|
33 |
-
|
34 |
-
# # # if __name__=='__main__':
|
35 |
-
# # # uvicorn.run('main:app', reload=True)
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
# # #uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
41 |
-
#
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
# # # from fastapi import FastAPI
|
48 |
-
# # # from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
49 |
-
# # # import librosa
|
50 |
-
# # # import uvicorn
|
51 |
-
|
52 |
-
# # # app = FastAPI()
|
53 |
-
|
54 |
-
# # # # Load model and processor
|
55 |
-
# # # processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
56 |
-
# # # model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
|
57 |
-
# # # model.config.forced_decoder_ids = None
|
58 |
-
|
59 |
-
# # # # Path to your audio file
|
60 |
-
# # # audio_file_path = "/home/pranjal/Downloads/output.mp3"
|
61 |
-
|
62 |
-
# # # # Read the audio file
|
63 |
-
# # # audio_data, _ = librosa.load(audio_file_path, sr=16000)
|
64 |
-
|
65 |
-
# # # @app.get("/")
|
66 |
-
# # # def transcribe_audio():
|
67 |
-
# # # # Process the audio data using the Whisper processor
|
68 |
-
# # # input_features = processor(audio_data.tolist(), return_tensors="pt").input_features
|
69 |
-
|
70 |
-
# # # # Generate transcription
|
71 |
-
# # # predicted_ids = model.generate(input_features)
|
72 |
-
# # # transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
73 |
-
|
74 |
-
# # # return {"transcription": transcription[0]}
|
75 |
-
|
76 |
-
# # # if __name__ == "__main__":
|
77 |
-
# # # import uvicorn
|
78 |
-
# # # uvicorn.run(app, host="0.0.0.0", port=8000)
|
79 |
-
|
80 |
-
|
81 |
-
# # # if __name__=='__app__':
|
82 |
-
# # # uvicorn.run('main:app', reload=True)
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
# # from fastapi import FastAPI, UploadFile, File
|
89 |
-
# # from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
90 |
-
# # import librosa
|
91 |
-
# # from fastapi.responses import HTMLResponse
|
92 |
-
# # import uvicorn
|
93 |
-
# # import io
|
94 |
-
|
95 |
-
# # app = FastAPI()
|
96 |
-
|
97 |
-
# # # Load model and processor
|
98 |
-
# # processor = WhisperProcessor.from_pretrained("openai/whisper-small")
|
99 |
-
# # model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
|
100 |
-
# # model.config.forced_decoder_ids = None
|
101 |
-
|
102 |
-
# # @app.get("/")
|
103 |
-
# # def read_root():
|
104 |
-
# # html_form = """
|
105 |
-
# # <html>
|
106 |
-
# # <body>
|
107 |
-
# # <h2>ASR Transcription</h2>
|
108 |
-
# # <form action="/transcribe" method="post" enctype="multipart/form-data">
|
109 |
-
# # <label for="audio_file">Upload an audio file (MP3 or WAV):</label>
|
110 |
-
# # <input type="file" id="audio_file" name="audio_file" accept=".mp3, .wav" required><br><br>
|
111 |
-
# # <input type="submit" value="Transcribe">
|
112 |
-
# # </form>
|
113 |
-
# # </body>
|
114 |
-
# # </html>
|
115 |
-
# # """
|
116 |
-
# # return HTMLResponse(content=html_form, status_code=200)
|
117 |
-
|
118 |
-
# # @app.post("/transcribe")
|
119 |
-
# # async def transcribe_audio(audio_file: UploadFile):
|
120 |
-
# # try:
|
121 |
-
# # # Read the uploaded audio file
|
122 |
-
# # audio_data = await audio_file.read()
|
123 |
-
|
124 |
-
# # # Process the audio data using the Whisper processor
|
125 |
-
# # audio_data, _ = librosa.load(io.BytesIO(audio_data), sr=16000)
|
126 |
-
# # input_features = processor(audio_data.tolist(), return_tensors="pt").input_features
|
127 |
-
|
128 |
-
# # # Generate transcription
|
129 |
-
# # predicted_ids = model.generate(input_features)
|
130 |
-
# # transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
131 |
-
|
132 |
-
# # return {"transcription": transcription[0]}
|
133 |
-
# # except Exception as e:
|
134 |
-
# # return {"error": str(e)}
|
135 |
-
|
136 |
-
# # if __name__ == "__app__":
|
137 |
-
# # uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
# #uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
144 |
-
|
145 |
-
|
146 |
-
# from fastapi import FastAPI, UploadFile, File
|
147 |
-
# from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
148 |
-
# import librosa
|
149 |
-
# from fastapi.responses import HTMLResponse
|
150 |
-
# import uvicorn
|
151 |
-
# import io
|
152 |
-
|
153 |
-
# app = FastAPI()
|
154 |
-
|
155 |
-
# # # Load model and processor
|
156 |
-
# # processor = WhisperProcessor.from_pretrained("openai/whisper-medium")
|
157 |
-
# # model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-medium")
|
158 |
-
# # model.config.forced_decoder_ids = None
|
159 |
-
|
160 |
-
# import whisper
|
161 |
-
# model = whisper.load_model("small")
|
162 |
-
|
163 |
-
|
164 |
-
# @app.get("/")
|
165 |
-
# def read_root():
|
166 |
-
# html_form = """
|
167 |
-
# <html>
|
168 |
-
# <body>
|
169 |
-
# <h2>ASR Transcription</h2>
|
170 |
-
# <form action="/transcribe" method="post" enctype="multipart/form-data">
|
171 |
-
# <label for="audio_file">Upload an audio file (MP3 or WAV):</label>
|
172 |
-
# <input type="file" id="audio_file" name="audio_file" accept=".mp3, .wav" required><br><br>
|
173 |
-
# <input type="submit" value="Transcribe">
|
174 |
-
# </form>
|
175 |
-
# </body>
|
176 |
-
# </html>
|
177 |
-
# """
|
178 |
-
# return HTMLResponse(content=html_form, status_code=200)
|
179 |
-
|
180 |
-
# @app.post("/transcribe")
|
181 |
-
# async def transcribe_audio(audio_file: UploadFile):
|
182 |
-
# try:
|
183 |
-
# # Read the uploaded audio file
|
184 |
-
# audio_data = await audio_file.read()
|
185 |
-
|
186 |
-
# # Process the audio data using the Whisper processor
|
187 |
-
# # audio_data, _ = librosa.load(io.BytesIO(audio_data), sr=16000)
|
188 |
-
# # input_features = processor(audio_data.tolist(), return_tensors="pt").input_features
|
189 |
-
|
190 |
-
# # # Generate transcription
|
191 |
-
# # predicted_ids = model.generate(input_features)
|
192 |
-
# # transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
193 |
-
# result = model.transcribe("/home/pranjal/Downloads/rt.mp3")
|
194 |
-
|
195 |
-
# return {"transcription": result['text']}
|
196 |
-
# except Exception as e:
|
197 |
-
# return {"error": str(e)}
|
198 |
-
|
199 |
-
# # if __name__ == "__app__":
|
200 |
-
# # uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)
|
201 |
-
|
202 |
#uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
203 |
|
204 |
from fastapi import FastAPI, UploadFile, File
|
@@ -261,5 +60,4 @@ async def transcribe_audio(audio_file: UploadFile):
|
|
261 |
final_transcription = " ".join(transcription)
|
262 |
final_transcription = remove_tags(final_transcription)
|
263 |
|
264 |
-
return final_transcription
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#uvicorn app:app --host 0.0.0.0 --port 8000 --reload
|
2 |
|
3 |
from fastapi import FastAPI, UploadFile, File
|
|
|
60 |
final_transcription = " ".join(transcription)
|
61 |
final_transcription = remove_tags(final_transcription)
|
62 |
|
63 |
+
return final_transcription
|
|