duatanzeel commited on
Commit
a361047
Β·
verified Β·
1 Parent(s): 9eebc6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -35
app.py CHANGED
@@ -1,40 +1,29 @@
1
  import streamlit as st
2
- from transformers import pipeline
3
- from huggingface_hub import login
4
- import os
5
 
6
- HF_TOKEN = os.getenv("HUGGINGFACEHUB_API_TOKEN")
7
- login(HF_TOKEN)
 
 
8
 
9
- st.title("πŸ€–πŸ“Ÿ Arduino Expert Chatbot")
10
- st.markdown("Ask anything about Arduino: code, circuits, projects!")
 
 
 
 
 
 
 
11
 
12
- @st.cache_resource
13
- def load_model():
14
- try:
15
- model = pipeline(
16
- "text-generation",
17
- model="tiiuae/falcon-7b-instruct", # lightweight, non-gated
18
- token=HF_TOKEN
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
- model = load_model()
27
-
28
- query = st.text_area("Ask your Arduino question here πŸ‘‡", height=150)
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")