Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,29 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
from huggingface_hub import login
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
)
|
| 20 |
-
return model
|
| 21 |
-
except Exception as e:
|
| 22 |
-
print(f"Model load failed: {e}")
|
| 23 |
-
st.error("β Failed to load model.")
|
| 24 |
-
return pipeline("text-generation", model="gpt2")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
if st.button("Get Answer"):
|
| 31 |
-
if query.strip():
|
| 32 |
-
with st.spinner("Thinking... π€"):
|
| 33 |
-
try:
|
| 34 |
-
prompt = f"<s>[INST] {query} [/INST]"
|
| 35 |
-
response = model(prompt, max_new_tokens=512, do_sample=True, temperature=0.7)
|
| 36 |
-
st.success(response[0]['generated_text'])
|
| 37 |
-
except Exception as e:
|
| 38 |
-
st.error(f"β Error generating response: {e}")
|
| 39 |
-
else:
|
| 40 |
-
st.warning("Please enter a valid question.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import random
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Page title
|
| 5 |
+
st.set_page_config(page_title="π² Dice Roller Story Bot", page_icon="π²")
|
| 6 |
+
st.title("π² Dice Roller + Mini Story Bot")
|
| 7 |
+
st.markdown("Click the button to roll a dice and see what happens in your story!")
|
| 8 |
|
| 9 |
+
# Define dice roll outcomes
|
| 10 |
+
story_outcomes = {
|
| 11 |
+
1: "π§ You encountered a zombie and ran for your life!",
|
| 12 |
+
2: "π° You found a hidden treasure under a tree!",
|
| 13 |
+
3: "π A dragon appeared... but it just wanted a hug.",
|
| 14 |
+
4: "π‘οΈ You discovered an ancient shield with magical powers!",
|
| 15 |
+
5: "π You ate a glowing mushroom and now you can talk to animals.",
|
| 16 |
+
6: "π³οΈ You fell into a secret tunnel leading to a lost kingdom!"
|
| 17 |
+
}
|
| 18 |
|
| 19 |
+
# Roll the dice
|
| 20 |
+
if st.button("Roll the Dice π²"):
|
| 21 |
+
roll = random.randint(1, 6)
|
| 22 |
+
st.subheader(f"You rolled a **{roll}**!")
|
| 23 |
+
st.success(story_outcomes[roll])
|
| 24 |
+
else:
|
| 25 |
+
st.info("Ready to roll? Click the button above!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Footer
|
| 28 |
+
st.markdown("---")
|
| 29 |
+
st.caption("Made with β€οΈ using Streamlit and Hugging Face Spaces")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|