Felguk commited on
Commit
d6ad142
·
verified ·
1 Parent(s): 6d05e81

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +68 -1
README.md CHANGED
@@ -177,4 +177,71 @@ trainer = Trainer(
177
  )
178
 
179
  # Обучение модели
180
- trainer.train()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  )
178
 
179
  # Обучение модели
180
+ trainer.train()
181
+ ```
182
+ ## Deploy Space
183
+
184
+ Вы можете легко развернуть модель `felguk-audio.box` в [Hugging Face Spaces](https://huggingface.co/spaces) с помощью Gradio или Streamlit. Вот пошаговое руководство:
185
+
186
+ ### Использование Gradio
187
+
188
+ 1. Установите Gradio:
189
+
190
+ ```bash
191
+ pip install gradio
192
+ ```
193
+ Создать app.py:
194
+ ```bash
195
+ import gradio as gr
196
+ from transformers import AutoModelForAudioClassification, AutoFeatureExtractor
197
+ import torchaudio
198
+
199
+ # Загрузка модели и feature extractor
200
+ model_name = "felguk-audio.box"
201
+ model = AutoModelForAudioClassification.from_pretrained(model_name)
202
+ feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
203
+
204
+ # Функция для классификации аудио
205
+ def classify_audio(audio_file):
206
+ waveform, sample_rate = torchaudio.load(audio_file)
207
+ inputs = feature_extractor(waveform.squeeze().numpy(), sampling_rate=sample_rate, return_tensors="pt")
208
+ with torch.no_grad():
209
+ logits = model(**inputs).logits
210
+ predicted_class_idx = logits.argmax(-1).item()
211
+ return model.config.id2label[predicted_class_idx]
212
+
213
+ # Создание интерфейса Gradio
214
+ interface = gr.Interface(
215
+ fn=classify_audio,
216
+ inputs=gr.Audio(type="filepath"),
217
+ outputs="text",
218
+ title="felguk-audio.box: Audio Classification",
219
+ description="Upload an audio file to classify it using the felguk-audio.box model."
220
+ )
221
+
222
+ # Запуск интерфейса
223
+ interface.launch()
224
+ ```
225
+ Потом надо добавить requirements.txt:
226
+ ```bash
227
+ torch
228
+ torchaudio
229
+ transformers
230
+ gradio
231
+ ```
232
+ ## Gr load
233
+ Вы можете загрузить модель с помощью gr load:
234
+ ```bash
235
+ import gradio as gr
236
+
237
+ # Загрузка модели через Hugging Face
238
+ model_interface = gr.load(
239
+ "models/felguk-audio.box", # Укажите путь к вашей модели
240
+ title="felguk-audio.box: Audio Classification",
241
+ description="Upload an audio file to classify it using the felguk-audio.box model."
242
+ )
243
+
244
+ # Запуск интерфейса
245
+ model_interface.launch()
246
+ ```
247
+