Harshithtd commited on
Commit
793fa09
·
verified ·
1 Parent(s): 677ec5f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torchaudio
4
+ import time
5
+
6
+ # Load Whisper ASR model
7
+ transcriber = pipeline(model="openai/whisper-base")
8
+
9
+ # Load summarization model
10
+ summarization_model = pipeline("summarization")
11
+
12
+ # Load question-answering model
13
+ model_name = "deepset/roberta-base-squad2"
14
+ nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
15
+
16
+ def translate_audio(audio):
17
+ # Step 1: Transcribe audio to text
18
+ transcription = transcriber(audio)
19
+ print('transcription', transcription)
20
+
21
+ # Step 2: Translate text to Hindi
22
+ summary = summarization_model(transcription['text'])
23
+ print('summary', summary)
24
+
25
+ return transcription['text'], summary[0]['summary_text']
26
+
27
+ def answer_question(context, question):
28
+ QA_input = {
29
+ 'question': question,
30
+ 'context': context
31
+ }
32
+ print('----QA_input----', QA_input)
33
+ return nlp(QA_input)['answer']
34
+
35
+ # Create Gradio interface
36
+ with gr.Blocks() as iface:
37
+ gr.Markdown("# Audio Translator, Summarizer, and QA System")
38
+
39
+ with gr.Row():
40
+ audio_input = gr.Audio(type="filepath", label="Upload Audio")
41
+ transcription_output = gr.Textbox(
42
+ label="Transcribed Text",
43
+ info="Initial text")
44
+ translation_output = gr.Textbox(
45
+ label="Summary",
46
+ info="Meeting minute")
47
+
48
+ translate_button = gr.Button("Translate Audio")
49
+
50
+ translate_button.click(
51
+ translate_audio,
52
+ inputs=[audio_input],
53
+ outputs=[transcription_output, translation_output]
54
+ )
55
+
56
+ def respond(message, chat_history, context):
57
+ bot_message = answer_question(context, message)
58
+ print('----bot_message---', bot_message)
59
+ chat_history.append((message, bot_message))
60
+ time.sleep(2)
61
+ return "", chat_history
62
+
63
+ with gr.Blocks() as demo:
64
+ chatbot = gr.Chatbot()
65
+ msg = gr.Textbox()
66
+ clear = gr.ClearButton([msg, chatbot])
67
+
68
+ msg.submit(respond, [msg, chatbot, transcription_output], [msg, chatbot])
69
+
70
+ # Launch the app
71
+ iface.launch(share=True) # 'share=True' to get a public link