import gradio as gr from transformers import pipeline from gtts import gTTS import os from pydub import AudioSegment from pydub.playback import play # Load a public model for question answering qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad") # Function to generate the answer and dinosaur speech def answer_question(question): context = "Provide the context or text where the answer should be found." result = qa_pipeline(question=question, context=context) answer = result['answer'] # Generate speech tts = gTTS(text=answer, lang='en') tts.save("answer.mp3") # Play the speech audio = AudioSegment.from_mp3("answer.mp3") play(audio) return answer, "answer.mp3" # HTML for the dinosaur image as background image_html = """ """ # Define Gradio interface iface = gr.Blocks() with iface: gr.Markdown( """ # Ancient Interface with Modern Dinosaur Ask a question and get an answer from our modern dinosaur! """ ) with gr.Row(): question_input = gr.Textbox(label="Ask a Question") answer_text = gr.Textbox(label="Answer") audio_output = gr.Audio(label="Dinosaur Speech") question_input.change(answer_question, inputs=question_input, outputs=[answer_text, audio_output]) gr.HTML(image_html) # Launch the interface iface.launch(share=True)