CodeNine commited on
Commit
4250f66
Β·
verified Β·
1 Parent(s): 69c5d57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -2,24 +2,26 @@ import streamlit as st
2
  import requests
3
  import os
4
 
5
- # Load Groq API key
6
  GROQ_API_KEY = os.getenv("GROQ_API_KEY")
7
 
 
8
  if not GROQ_API_KEY:
9
- st.error("❌ GROQ_API_KEY not found! Please add it in Settings β†’ Secrets.")
10
  st.stop()
11
 
12
  # App UI
13
  st.set_page_config(page_title="Groq Battle Arena", page_icon="βš”οΈ")
14
  st.title("βš”οΈ Groq Battle Arena")
15
- st.markdown("Choose your fighter and generate an epic AI battle scene!")
16
 
17
- # Character classes
18
  classes = ["πŸ”₯ Fire Knight", "❄️ Ice Mage", "🩸 Shadow Assassin", "⚑ Storm Archer", "πŸ‰ Dragon Tamer"]
19
  selected_class = st.selectbox("Select Your Warrior:", classes)
20
 
 
21
  if st.button("βš”οΈ Enter the Arena"):
22
- with st.spinner("Groq is writing your battle..."):
23
 
24
  prompt = f"""
25
  Write a cinematic fantasy battle scene for a hero who is a {selected_class}.
@@ -38,19 +40,21 @@ if st.button("βš”οΈ Enter the Arena"):
38
 
39
  json_data = {
40
  "model": "llama3-8b-8192",
41
- "messages": [
42
- {"role": "user", "content": prompt}
43
- ],
44
  "temperature": 0.9,
45
  "max_tokens": 700,
46
  "top_p": 1
47
  }
48
 
49
  try:
50
- res = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=json_data)
51
- output = res.json()['choices'][0]['message']['content']
52
  st.success("βš”οΈ Battle Generated!")
53
  st.markdown(f"```markdown\n{output}\n```")
54
 
55
  except Exception as e:
56
  st.error(f"❌ Error: {e}")
 
 
 
 
 
2
  import requests
3
  import os
4
 
5
+ # Load Groq API key from Hugging Face Secrets
6
  GROQ_API_KEY = os.getenv("GROQ_API_KEY")
7
 
8
+ # Check API key
9
  if not GROQ_API_KEY:
10
+ st.error("❌ GROQ_API_KEY not found! Add it in Settings β†’ Secrets.")
11
  st.stop()
12
 
13
  # App UI
14
  st.set_page_config(page_title="Groq Battle Arena", page_icon="βš”οΈ")
15
  st.title("βš”οΈ Groq Battle Arena")
16
+ st.markdown("Choose your fighter and generate an epic AI battle scene powered by LLaMA 3!")
17
 
18
+ # Character selection
19
  classes = ["πŸ”₯ Fire Knight", "❄️ Ice Mage", "🩸 Shadow Assassin", "⚑ Storm Archer", "πŸ‰ Dragon Tamer"]
20
  selected_class = st.selectbox("Select Your Warrior:", classes)
21
 
22
+ # Generate battle on button click
23
  if st.button("βš”οΈ Enter the Arena"):
24
+ with st.spinner("Summoning your battle..."):
25
 
26
  prompt = f"""
27
  Write a cinematic fantasy battle scene for a hero who is a {selected_class}.
 
40
 
41
  json_data = {
42
  "model": "llama3-8b-8192",
43
+ "messages": [{"role": "user", "content": prompt}],
 
 
44
  "temperature": 0.9,
45
  "max_tokens": 700,
46
  "top_p": 1
47
  }
48
 
49
  try:
50
+ response = requests.post("https://api.groq.com/openai/v1/chat/completions", headers=headers, json=json_data)
51
+ output = response.json()['choices'][0]['message']['content']
52
  st.success("βš”οΈ Battle Generated!")
53
  st.markdown(f"```markdown\n{output}\n```")
54
 
55
  except Exception as e:
56
  st.error(f"❌ Error: {e}")
57
+
58
+ # Optional bottom message to help Hugging Face recognize app
59
+ if __name__ == "__main__":
60
+ st.write("βœ… App initialized.")