Spaces:
Sleeping
Sleeping
| 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() | |