import gradio as gr
import random
import base64
# Mad Lib Generator
templates = [
"The {adjective} {noun} {verb} over the {adjective} {noun}.",
"In a {adjective} land, a {noun} and a {noun} went on a {adjective} adventure.",
"The {noun} {verb} {adverb} while the {adjective} {noun} watched in amazement."
]
parts_of_speech = {
"adjective": ["brave", "mysterious", "colorful", "gigantic", "tiny"],
"noun": ["wizard", "dragon", "knight", "castle", "forest"],
"verb": ["flew", "danced", "sang", "fought", "explored"],
"adverb": ["quickly", "silently", "gracefully", "fiercely", "carefully"]
}
def generate_mad_lib():
template = random.choice(templates)
for part in parts_of_speech:
while "{" + part + "}" in template:
template = template.replace("{" + part + "}", random.choice(parts_of_speech[part]), 1)
return template
# Kaboom.js Breakout Game HTML
kaboom_game_html = """
"""
# A-Frame 3D Scene HTML
aframe_scene_html = """
"""
def upload_model(file):
if file is not None:
file_extension = file.name.split('.')[-1].lower()
encoded_file = base64.b64encode(file.read()).decode()
data_url = f"data:application/octet-stream;base64,{encoded_file}"
load_model_js = f"""
"""
return aframe_scene_html + load_model_js
return aframe_scene_html
# Define the Gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Game Development and 3D Content Showcase")
with gr.Tab("Breakout Game"):
gr.HTML(kaboom_game_html)
with gr.Tab("Mad Lib Generator"):
mad_lib_button = gr.Button("Generate Mad Lib")
mad_lib_output = gr.Textbox(label="Generated Mad Lib")
mad_lib_button.click(generate_mad_lib, inputs=None, outputs=mad_lib_output)
with gr.Tab("A-Frame 3D Scene"):
model_upload = gr.File(label="Upload 3D Model (OBJ or GLB)")
scene_output = gr.HTML(aframe_scene_html)
model_upload.upload(upload_model, inputs=model_upload, outputs=scene_output)
# Launch the Gradio app
if __name__ == "__main__":
demo.launch()