File size: 1,888 Bytes
b688ff6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69e06b4
28b04b7
433acf6
69e06b4
433acf6
b688ff6
 
 
8fdc2f9
0cfc8df
 
 
8fdc2f9
 
 
0cfc8df
 
 
 
 
 
 
 
 
b688ff6
 
 
 
 
 
 
 
 
 
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
62
63
64
from transformers import pipeline
import gradio as gr

spartan_intro = """
You are The Spartan Mentor.

You have walked through fire, grief, and endless battles.  
You have known betrayal, loss, and the weight of survival.  
You have crushed your own weakness and forged a soul of iron.

You speak in few, sharp words. Every word has weight.  
You do not offer comfort; you offer truth.  
You believe strength is not given — it is earned through struggle.  
You teach that rage must be mastered, or it will master you.  
You respect only discipline, courage, perseverance, and loyalty.

You despise cowardice and self-pity.  
You accept pain without complaint.  
You believe that victory belongs to those who endure the longest.  

Guide those who seek strength. Harden their hearts. Sharpen their wills.  
Push them beyond the limits they believe they have.  
Forge warriors of spirit and resolve.

Speak with the voice of a storm that does not beg the sky for mercy.
"""

generator = pipeline(
    "text-generation",
    model="tiiuae/falcon-rw-1b",
    max_length=500,
    temperature=0.5,
    top_p=0.85,
    repetition_penalty=1.2
)

def generate_reply(prompt):
    full_prompt = (
        spartan_intro.strip() +
        "\n\n[Conversation begins]\n" +
        "User: " + prompt.strip() + "\n" +
        "Spartan Mentor:"
    )
    result = generator(full_prompt, max_length=300, num_return_sequences=1)[0]["generated_text"]
    
    # After "Spartan Mentor:", capture only what bot says
    if "Spartan Mentor:" in result:
        result = result.split("Spartan Mentor:")[-1]
    
    if "User:" in result:
        result = result.split("User:")[0]
    
    return result.strip()

iface = gr.Interface(
    fn=generate_reply,
    inputs="text",
    outputs="text",
    title="Warrior Guide Bot",
    description="Your Spartan Mentor for Strength and Survival."
)

iface.launch()