Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Define the story in English and Arabic
|
| 6 |
+
story = {
|
| 7 |
+
"start": {
|
| 8 |
+
"en": "Welcome, Detective! The heirloom has gone missing during the party. Do you want to investigate the crime scene or interview the suspects?",
|
| 9 |
+
"ar": "مرحبًا، أيها المحقق! لقد اختفى التُحفة أثناء الحفلة. هل تريد التحقيق في مسرح الجريمة أو مقابلة المشتبه بهم؟",
|
| 10 |
+
"choices": {
|
| 11 |
+
"investigate": "crime_scene",
|
| 12 |
+
"interview": "suspects"
|
| 13 |
+
}
|
| 14 |
+
},
|
| 15 |
+
"crime_scene": {
|
| 16 |
+
"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?",
|
| 17 |
+
"ar": "في مسرح الجريمة، تجد مزهرية مكسورة وبعض بصمات الأصابع. هل تريد فحص بصمات الأصابع أم التحقق من قائمة الضيوف؟",
|
| 18 |
+
"choices": {
|
| 19 |
+
"fingerprints": "fingerprints",
|
| 20 |
+
"guest_list": "guest_list"
|
| 21 |
+
}
|
| 22 |
+
},
|
| 23 |
+
"fingerprints": {
|
| 24 |
+
"en": "The fingerprints lead you to a suspect. Do you want to question this suspect or investigate further?",
|
| 25 |
+
"ar": "البصمات تقودك إلى مشتبه به. هل تريد سؤال هذا المشتبه به أم التحقيق بشكل أعمق؟",
|
| 26 |
+
"choices": {
|
| 27 |
+
"question": "suspect",
|
| 28 |
+
"investigate": "additional_clues"
|
| 29 |
+
}
|
| 30 |
+
},
|
| 31 |
+
"guest_list": {
|
| 32 |
+
"en": "The guest list reveals that an unexpected guest attended. Do you want to question this guest or examine the broken vase?",
|
| 33 |
+
"ar": "تكشف قائمة الضيوف أن هناك ضيفًا غير متوقع حضر. هل تريد سؤال هذا الضيف أم فحص المزهرية المكسورة؟",
|
| 34 |
+
"choices": {
|
| 35 |
+
"question": "unexpected_guest",
|
| 36 |
+
"vase": "broken_vase"
|
| 37 |
+
}
|
| 38 |
+
},
|
| 39 |
+
"broken_vase": {
|
| 40 |
+
"en": "The vase was used to hide the stolen heirloom. You find the heirloom hidden inside it! Case solved.",
|
| 41 |
+
"ar": "استخدمت المزهرية لإخفاء التُحفة المسروقة. تجد التُحفة مخبأة بداخلها! القضية تم حلها.",
|
| 42 |
+
"choices": {}
|
| 43 |
+
},
|
| 44 |
+
"additional_clues": {
|
| 45 |
+
"en": "Further investigation leads you to more evidence. Combining clues from the scene, you find the thief! Case solved.",
|
| 46 |
+
"ar": "التحقيق الإضافي يقودك إلى مزيد من الأدلة. من خلال دمج الأدلة من المشهد، تجد السارق! القضية تم حلها.",
|
| 47 |
+
"choices": {}
|
| 48 |
+
},
|
| 49 |
+
"suspect": {
|
| 50 |
+
"en": "The suspect confesses to the theft. The heirloom is recovered and the case is solved!",
|
| 51 |
+
"ar": "المشتبه به يعترف بالسرقة. التُحفة تم استرجاعها والقضية تم حلها!",
|
| 52 |
+
"choices": {}
|
| 53 |
+
},
|
| 54 |
+
"unexpected_guest": {
|
| 55 |
+
"en": "The unexpected guest is found with the heirloom. The case is closed!",
|
| 56 |
+
"ar": "الضيف غير المتوقع يُعثر عليه مع التُحفة. القضية مغلقة!",
|
| 57 |
+
"choices": {}
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
# Define the image paths
|
| 62 |
+
image_paths = {
|
| 63 |
+
"start": "start.jpg",
|
| 64 |
+
"crime_scene": "crime_scene.jpg",
|
| 65 |
+
"fingerprints": "fingerprints.jpg",
|
| 66 |
+
"guest_list": "guest_list.jpg",
|
| 67 |
+
"broken_vase": "broken_vase.jpg",
|
| 68 |
+
"additional_clues": "additional_clues.jpg",
|
| 69 |
+
"suspect": "suspect.jpg",
|
| 70 |
+
"unexpected_guest": "unexpected_guest.jpg"
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
def get_scene(scene, language):
|
| 74 |
+
# Return the scene text and the corresponding image based on language
|
| 75 |
+
scene_info = story.get(scene, {"text": "Unknown scene", "choices": {}})
|
| 76 |
+
text = scene_info.get(language, "Text not available")
|
| 77 |
+
image_path = image_paths.get(scene, "default.jpg")
|
| 78 |
+
if os.path.exists(image_path):
|
| 79 |
+
img = Image.open(image_path)
|
| 80 |
+
else:
|
| 81 |
+
img = Image.new("RGB", (640, 480), color="white") # Default image if path is incorrect
|
| 82 |
+
return text, img, scene_info["choices"]
|
| 83 |
+
|
| 84 |
+
def detective_game(language, choice):
|
| 85 |
+
# Update the scene based on user choice and language
|
| 86 |
+
next_scene = story["start"]["choices"].get(choice, "start")
|
| 87 |
+
return get_scene(next_scene, language)
|
| 88 |
+
|
| 89 |
+
# Create Gradio interface
|
| 90 |
+
interface = gr.Interface(
|
| 91 |
+
fn=detective_game,
|
| 92 |
+
inputs=[
|
| 93 |
+
gr.Radio(choices=["en", "ar"], label="Choose Language"),
|
| 94 |
+
gr.Dropdown(choices=["investigate", "interview"], label="Choose an action")
|
| 95 |
+
],
|
| 96 |
+
outputs=[gr.Textbox(), gr.Image(type="pil")],
|
| 97 |
+
title="Detective Conan: The Case of the Missing Heirloom",
|
| 98 |
+
description="Help solve the mystery of the missing heirloom by making choices. Choose your language and start investigating!"
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
interface.launch()
|