File size: 1,392 Bytes
3617789
 
 
 
 
 
 
 
 
eb3fe64
3617789
 
 
 
 
 
 
 
eb3fe64
3617789
 
 
 
 
 
 
 
 
 
 
eb3fe64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37dac4c
42f7207
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
55
56
57
58
59
60
61
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)