File size: 1,801 Bytes
47ac33e
 
 
 
 
 
 
25ad9b7
 
47ac33e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7606b5
2ea074d
25ad9b7
 
 
 
e7606b5
 
 
 
 
 
 
 
25ad9b7
 
 
 
 
 
 
47ac33e
4418c96
 
 
 
 
 
 
 
 
 
 
 
 
47ac33e
4418c96
 
 
47ac33e
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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 = """
<!DOCTYPE html>
<html>
<head>
    <style>
        body { 
            margin: 0; 
            height: 100vh;
            background-image: url('https://i.pinimg.com/736x/b6/e8/61/b6e86149d3180b11018d9c3de1af92e6.jpg');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }
    </style>
</head>
<body>
</body>
</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)