File size: 4,827 Bytes
7b37b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import gradio as gr
from PIL import Image
import os

# 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")
    if os.path.exists(image_path):
        img = Image.open(image_path)
    else:
        img = Image.new("RGB", (640, 480), color="white")  # Default image if path is incorrect
    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()