Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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!
|
| 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
|
| 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("
|
| 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 |
-
|
| 51 |
-
output =
|
| 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.")
|