Update app.py
Browse files
app.py
CHANGED
@@ -125,4 +125,59 @@ def toggle_hint_mode():
|
|
125 |
"Hint Mode: ON" if state["hint_mode"] else "Hint Mode: OFF",
|
126 |
gr.update(visible=True)
|
127 |
)
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
"Hint Mode: ON" if state["hint_mode"] else "Hint Mode: OFF",
|
126 |
gr.update(visible=True)
|
127 |
)
|
128 |
+
import gradio as gr
|
129 |
+
|
130 |
+
with gr.Blocks(title="Kasoti") as demo:
|
131 |
+
gr.Markdown("## 🧠 Kasoti")
|
132 |
+
gr.Markdown("Think of something. I will try to guess it in 20 yes/no questions. "
|
133 |
+
"Answer with **yes/no** or **ہاں/نہیں**.")
|
134 |
+
|
135 |
+
with gr.Row():
|
136 |
+
start = gr.Button("🎲 Start Game", scale=1)
|
137 |
+
hint_toggle = gr.Button("💡 Toggle Hint Mode", scale=1)
|
138 |
+
hint_status = gr.Textbox(value="Hint Mode: OFF", show_label=False, interactive=False)
|
139 |
+
|
140 |
+
with gr.Row():
|
141 |
+
with gr.Column(scale=1):
|
142 |
+
gr.Markdown("### 🎤 Input")
|
143 |
+
lang_sel = gr.CheckboxGroup(["English", "Urdu"], label="Select Language", value=["English"])
|
144 |
+
mic_input = gr.Audio(sources=["microphone"], type="numpy", label="Record Your Answer")
|
145 |
+
transcribe = gr.Button("🎙️ Transcribe")
|
146 |
+
typed_ans = gr.Textbox(label="✍️ Or type your answer")
|
147 |
+
submit = gr.Button("✅ Submit Answer")
|
148 |
+
|
149 |
+
with gr.Column(scale=2):
|
150 |
+
gr.Markdown("### 🎮 Game Status")
|
151 |
+
game_q_box = gr.Textbox(label="🧩 Current Question", interactive=False, lines=2)
|
152 |
+
game_history = gr.Textbox(label="🧾 Hint / Status", interactive=False, lines=2)
|
153 |
+
final_answer_box = gr.Textbox(label="🎯 Final Answer", visible=False, lines=2, interactive=False)
|
154 |
+
|
155 |
+
# Button click events
|
156 |
+
start.click(
|
157 |
+
fn=begin_game,
|
158 |
+
outputs=[game_q_box, game_history, final_answer_box, submit, final_answer_box]
|
159 |
+
)
|
160 |
+
|
161 |
+
hint_toggle.click(
|
162 |
+
fn=toggle_hint_mode,
|
163 |
+
outputs=[hint_status, game_history]
|
164 |
+
)
|
165 |
+
|
166 |
+
hint_toggle.click(
|
167 |
+
fn=hint_response,
|
168 |
+
outputs=[game_history]
|
169 |
+
)
|
170 |
+
|
171 |
+
transcribe.click(
|
172 |
+
fn=convert_audio_to_text,
|
173 |
+
inputs=[mic_input, lang_sel],
|
174 |
+
outputs=[typed_ans]
|
175 |
+
)
|
176 |
+
|
177 |
+
submit.click(
|
178 |
+
fn=interpret_answer,
|
179 |
+
inputs=[typed_ans],
|
180 |
+
outputs=[game_q_box, typed_ans, final_answer_box, game_history, final_answer_box]
|
181 |
+
)
|
182 |
+
|
183 |
+
demo.launch()
|