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()