File size: 1,402 Bytes
785f4dd
aec05f5
 
 
a264185
 
785f4dd
aec05f5
 
a264185
785f4dd
aec05f5
 
 
 
785f4dd
aec05f5
 
 
 
785f4dd
aec05f5
785f4dd
a264185
 
 
 
 
 
 
aec05f5
785f4dd
aec05f5
785f4dd
a264185
 
 
 
aec05f5
 
785f4dd
aec05f5
 
 
785f4dd
 
aec05f5
a264185
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import gradio as gr
from transformers import pipeline
from gtts import gTTS
import tempfile
import pygame
import time

# Load the question-answering model
model_name = "AVISHKAARAM/avishkaarak-ekta-hindi"
model = pipeline("question-answering", model=model_name)

def question_answering(context, question):
    # Use the question-answering model to get the answer
    result = model(context=context, question=question)
    answer = result["answer"]

    # Convert the answer to audio
    tts = gTTS(text=answer, lang='en')
    audio_path = tempfile.NamedTemporaryFile(suffix=".mp3").name
    tts.save(audio_path)

    return answer, audio_path

def play_audio(audio_path):
    pygame.mixer.init()
    pygame.mixer.music.load(audio_path)
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        time.sleep(0.1)

# Create the Gradio interface
iface = gr.Interface(
    fn=question_answering,
    inputs=["text", "text"],
    outputs=[
        gr.outputs.Textbox(label="Answer"),
        gr.outputs.Audio(label="Answer Audio", type="numpy")
    ],
    title="Question Answering - AVISHKAARAK",
    description="Enter a context and a question to get an answer. :)",
    examples=[
        ["The capital of France is Paris.", "What is the capital of France?"],
        ["OpenAI is famous for developing GPT-3.", "What is OpenAI known for?"],
    ],
)

# Run the interface
iface.launch()