SivaResearch commited on
Commit
c627930
·
verified ·
1 Parent(s): 932557f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -1,12 +1,20 @@
1
 
2
 
3
 
 
 
4
 
5
 
6
  import torch
7
  from transformers import AutoTokenizer, AutoModelForCausalLM
8
  import gradio as gr
9
 
 
 
 
 
 
 
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
12
  model_name = "ai4bharat/Airavata"
@@ -52,10 +60,40 @@ def inference(input_prompt, model, tokenizer):
52
  return output_text
53
 
54
 
55
- def chat_interface(message,history):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  outputs = inference(message, model, tokenizer)
57
  return outputs
58
 
59
 
60
- chat_interface = gr.ChatInterface(chat_interface, title="CAMAI")
61
- chat_interface.launch()
 
 
 
 
 
 
 
 
 
1
 
2
 
3
 
4
+ import whisper
5
+
6
 
7
 
8
  import torch
9
  from transformers import AutoTokenizer, AutoModelForCausalLM
10
  import gradio as gr
11
 
12
+
13
+ Asr_model = whisper.load_model("base")
14
+ Asr_model.device
15
+
16
+
17
+
18
  device = "cuda" if torch.cuda.is_available() else "cpu"
19
 
20
  model_name = "ai4bharat/Airavata"
 
60
  return output_text
61
 
62
 
63
+
64
+ def transcribe(audio):
65
+
66
+ #time.sleep(3)
67
+ # load audio and pad/trim it to fit 30 seconds
68
+ audio = whisper.load_audio(audio)
69
+ audio = whisper.pad_or_trim(audio)
70
+
71
+ # make log-Mel spectrogram and move to the same device as the model
72
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
73
+
74
+ # detect the spoken language
75
+ _, probs = model.detect_language(mel)
76
+ print(f"Detected language: {max(probs, key=probs.get)}")
77
+
78
+ # decode the audio
79
+ options = whisper.DecodingOptions()
80
+ result = whisper.decode(model, mel, options)
81
+ return result.text
82
+
83
+
84
+ def chat_interface(audio):
85
+ message = transcribe(audio)
86
  outputs = inference(message, model, tokenizer)
87
  return outputs
88
 
89
 
90
+ gr.Interface(
91
+ title = 'CAMAI - Centralized Actionable Multimodal Agri Assistant on Edge Intelligence for Farmers ',
92
+ fn=chat_interface,
93
+ inputs=[
94
+ gr.inputs.Audio(source="microphone", type="filepath")
95
+ ],
96
+ outputs=[
97
+ "textbox"
98
+ ],
99
+ live=True).launch()