import os import streamlit as st from groq import Groq # Initialize Groq client client = Groq(api_key=os.getenv("GROQ_API_KEY")) st.set_page_config(page_title="History Ruler Finder", layout="centered") st.title("📜 History Ruler Finder (API Powered)") st.write("Enter a country and year to find the ruling authority.") country = st.text_input("Country:") year = st.number_input("Year:", min_value=0, max_value=3000, step=1) if st.button("Find Ruler"): if country and year: prompt = f""" You are a history expert AI assistant. Task: Identify the ruling king, emperor, queen, dynasty, or ruling authority of a given country during a specific year. Rules: - Always give historically accurate information. - If the ruler changed during that year, mention both rulers with dates. - If the country was ruled by an empire or colonial power, clearly state that. - Keep the answer simple, clear, and educational. - If the country or year is unclear or did not exist, politely explain why. Output format (STRICT): Country: Year: Ruler: Additional Notes (optional): Country: {country} Year: {year} """ with st.spinner("Searching history..."): response = client.chat.completions.create( model="llama-3.1-8b-instant", messages=[{"role": "user", "content": prompt}] ) result = response.choices[0].message.content st.subheader("📌 Result") st.text(result) else: st.warning("Please enter both country and year.")