Hisory-Ruler-Ai / app.py
Habib U Rehman
Update app.py
42f7207 verified
import gradio as gr
import os
from groq import Groq
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
SYSTEM_PROMPT = """
You are a professional history expert AI assistant.
Always return:
- Ruler / Authority Name
- Period of Rule
- Region / Country
- Key Contributions (bullet points)
"""
def history_ruler(country, year):
if not country or not year:
return "Please enter both country and year."
response = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": f"Country: {country}\nYear: {year}"}
],
temperature=0.2
)
return response.choices[0].message.content
# πŸ”’ FORCE SQUARE OUTPUT USING CSS
css = """
#square-box textarea {
width: 400px !important;
height: 400px !important;
resize: none;
}
"""
with gr.Blocks(css=css) as app:
gr.Markdown("## πŸ›οΈ History Ruler Finder")
with gr.Row():
country = gr.Textbox(label="Country / Region", lines=2)
year = gr.Textbox(label="Year / Time Period", lines=2)
output = gr.Textbox(
label="Historical Information",
elem_id="square-box"
)
gr.Button("Find Ruler").click(
fn=history_ruler,
inputs=[country, year],
outputs=output
)
app.launch(share=True, debug=True)