Spaces:
Sleeping
Update app.py
Browse filesimport gradio as gr
from PIL import Image
# Define the story in English and Arabic
story = {
"start": {
"en": "Welcome, Detective! The heirloom has gone missing during the party. Do you want to investigate the crime scene or interview the suspects?",
"ar": "مرحبًا، أيها المحقق! لقد اختفى التُحفة أثناء الحفلة. هل تريد التحقيق في مسرح الجريمة أو مقابلة المشتبه بهم؟",
"choices": {
"investigate": "crime_scene",
"interview": "suspects"
}
},
"crime_scene": {
"en": "At the crime scene, you find a broken vase and a few fingerprints. Do you want to examine the fingerprints or check the guest list?",
"ar": "في مسرح الجريمة، تجد مزهرية مكسورة وبعض بصمات الأصابع. هل تريد فحص بصمات الأصابع أم التحقق من قائمة الضيوف؟",
"choices": {
"fingerprints": "fingerprints",
"guest_list": "guest_list"
}
},
"fingerprints": {
"en": "The fingerprints lead you to a suspect. Do you want to question this suspect or investigate further?",
"ar": "البصمات تقودك إلى مشتبه به. هل تريد سؤال هذا المشتبه به أم التحقيق بشكل أعمق؟",
"choices": {
"question": "suspect",
"investigate": "additional_clues"
}
},
"guest_list": {
"en": "The guest list reveals that an unexpected guest attended. Do you want to question this guest or examine the broken vase?",
"ar": "تكشف قائمة الضيوف أن هناك ضيفًا غير متوقع حضر. هل تريد سؤال هذا الضيف أم فحص المزهرية المكسورة؟",
"choices": {
"question": "unexpected_guest",
"vase": "broken_vase"
}
},
"broken_vase": {
"en": "The vase was used to hide the stolen heirloom. You find the heirloom hidden inside it! Case solved.",
"ar": "استخدمت المزهرية لإخفاء التُحفة المسروقة. تجد التُحفة مخبأة بداخلها! القضية تم حلها.",
"choices": {}
},
"additional_clues": {
"en": "Further investigation leads you to more evidence. Combining clues from the scene, you find the thief! Case solved.",
"ar": "التحقيق الإضافي يقودك إلى مزيد من الأدلة. من خلال دمج الأدلة من المشهد، تجد السارق! القضية تم حلها.",
"choices": {}
},
"suspect": {
"en": "The suspect confesses to the theft. The heirloom is recovered and the case is solved!",
"ar": "المشتبه به يعترف بالسرقة. التُحفة تم استرجاعها والقضية تم حلها!",
"choices": {}
},
"unexpected_guest": {
"en": "The unexpected guest is found with the heirloom. The case is closed!",
"ar": "الضيف غير المتوقع يُعثر عليه مع التُحفة. القضية مغلقة!",
"choices": {}
}
}
# Define the image paths
image_paths = {
"start": "start.jpg",
"crime_scene": "crime_scene.jpg",
"fingerprints": "fingerprints.jpg",
"guest_list": "guest_list.jpg",
"broken_vase": "broken_vase.jpg",
"additional_clues": "additional_clues.jpg",
"suspect": "suspect.jpg",
"unexpected_guest": "unexpected_guest.jpg"
}
def get_scene(scene, language):
# Return the scene text and the corresponding image based on language
scene_info = story.get(scene, {"text": "Unknown scene", "choices": {}})
text = scene_info.get(language, "Text not available")
image_path = image_paths.get(scene, "default.jpg")
img = Image.open(image_path)
return text, img, scene_info["choices"]
def detective_game(language, choice):
# Update the scene based on user choice and language
next_scene = story["start"]["choices"].get(choice, "start")
return get_scene(next_scene, language)
# Create Gradio interface
interface = gr.Interface(
fn=detective_game,
inputs=[
gr.Radio(choices=["en", "ar"], label="Choose Language"),
gr.Dropdown(choices=["investigate", "interview"], label="Choose an action")
],
outputs=[gr.Textbox(), gr.Image(type="pil")],
title="Detective Conan: The Case of the Missing Heirloom",
description="Help solve the mystery of the missing heirloom by making choices. Choose your language and start investigating!"
)
interface.launch()
|
@@ -1,23 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
def interactive_story(choice):
|
| 4 |
-
if choice == "Start Adventure":
|
| 5 |
-
return "You are at the edge of a mysterious forest. Do you want to go inside or stay outside? (Type 'inside' or 'outside')"
|
| 6 |
-
elif choice == "inside":
|
| 7 |
-
return "You encounter a wise old man. Do you ask him for advice or continue alone? (Type 'ask' or 'continue')"
|
| 8 |
-
elif choice == "ask":
|
| 9 |
-
return "The old man tells you a secret path to treasure. Congratulations, you found the treasure!"
|
| 10 |
-
elif choice == "continue":
|
| 11 |
-
return "You wander alone and find nothing. Better luck next time!"
|
| 12 |
-
else:
|
| 13 |
-
return "Please start the adventure by typing 'Start Adventure'."
|
| 14 |
-
|
| 15 |
-
interface = gr.Interface(
|
| 16 |
-
fn=interactive_story,
|
| 17 |
-
inputs=gr.Textbox(label="What will you do?"),
|
| 18 |
-
outputs="text",
|
| 19 |
-
title="Interactive Story Game",
|
| 20 |
-
description="Make choices to navigate through a story."
|
| 21 |
-
)
|
| 22 |
-
|
| 23 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|