File size: 1,523 Bytes
34bc649 8169c9b 34bc649 21b7328 8169c9b 34bc649 21b7328 8169c9b 21b7328 8169c9b 34bc649 21b7328 34bc649 8169c9b 34bc649 21b7328 | 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 | import gradio as gr
from gemini_client import ask_gemini, translate_to_bangla
from country_info import get_country_info # Uses restcountries.com
def ai_tour_guide(country_name):
if not country_name.strip():
return "⚠️ Please enter a country name.", "", ""
# Gemini Description
try:
english_text = ask_gemini(f"Tell me about {country_name}")
except Exception as e:
english_text = f"⚠️ Gemini error: {e}"
# Translate to Bangla
try:
bangla_text = translate_to_bangla(english_text)
except Exception as e:
bangla_text = f"⚠️ অনুবাদ ব্যর্থ হয়েছে: {e}"
# Country Info (capital, population)
try:
info = get_country_info(country_name)
if "error" in info:
raise ValueError(info["error"])
stats = f"Capital: {info.get('capital', 'N/A')}, Population: {info.get('population', 'N/A')}"
except Exception as e:
stats = f"⚠️ Country info error: {e}"
return english_text, bangla_text, stats
with gr.Blocks() as demo:
gr.Markdown("## 🌍 AI Tour Guide (English ➡️ Bangla)")
country = gr.Textbox(label="Enter a country name")
btn = gr.Button("Explore")
out_en = gr.Markdown(label="🇬🇧 Description (English)")
out_bn = gr.Markdown(label="🇧🇩 Description (Bengali)")
stats = gr.Markdown(label="🗺️ Quick Facts")
btn.click(fn=ai_tour_guide, inputs=country, outputs=[out_en, out_bn, stats])
demo.launch()
|