File size: 1,525 Bytes
cc20161 36564e3 cc20161 36564e3 cc20161 36564e3 cc20161 36564e3 | 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 | 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.")
|