abdullahrehan's picture
Update app.py
bb3dd8d verified
import streamlit as st
import os
from groq import Groq
# ------------------ GROQ CLIENT SETUP ------------------
os.environ["GROQ_API_KEY"] = st.secrets["GROQ_API_KEY"]
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
def chat_with_groq(prompt):
chat_completion = client.chat.completions.create(
messages=[
{"role": "user", "content": prompt}
],
model="llama-3.3-70b-versatile",
)
return chat_completion.choices[0].message.content
# ------------------ FANCY UI ------------------
st.set_page_config(page_title="Otaku Recommender", page_icon="🍿", layout="wide")
st.markdown("<h1 style='text-align: center; color: #f63366;'>🍿 Otaku Recommender AI</h1>", unsafe_allow_html=True)
# Step 1: Genre Selection
st.subheader("Step 1: Select your preferred genres")
genre_options = ['Romance', 'Isekai', 'Comedy', 'Horror', 'Hentai', 'Action', 'Drama', 'Fantasy', 'Mystery', 'Uncensored', 'Sci-Fi']
selected_genres = st.multiselect("Choose one or more genres:", genre_options)
# Step 2: Content Type
st.subheader("Step 2: Choose content type")
content_types = ['Anime', 'Manhwa', 'Manga', 'Webseries', 'Dramas', 'Movies']
content_choice = st.selectbox("Pick your content type:", content_types)
# Step 3: Frequency of Preference
st.subheader("Step 3: Rank your genre preferences (1–10)")
genre_freq = {}
for genre in selected_genres:
genre_freq[genre] = st.slider(f"{genre}", 1, 10, 5)
# Step 4: Request Suggestions
if st.button("🎯 Get Suggestions"):
preferences = f"You are an anime bot. The user prefers content type: {content_choice}. Genre preferences with frequency are: {genre_freq}. Recommend the 10 most relevant {content_choice} suggestions."
suggestions = chat_with_groq(preferences)
st.session_state['suggestions'] = suggestions
st.session_state['unseen'] = suggestions.split("\n")
# Step 5: Display and filter suggestions
if 'suggestions' in st.session_state:
st.subheader("πŸŽ₯ Top Suggestions")
for i, title in enumerate(st.session_state['unseen'], 1):
st.markdown(f"**{i}. {title.strip()}**")
watched = st.multiselect("Mark what you've already watched/read:", st.session_state['unseen'])
if st.button("πŸ” Refresh Suggestions"):
for w in watched:
if w in st.session_state['unseen']:
st.session_state['unseen'].remove(w)
st.rerun()
# Step 6: Spoiler Request
if 'unseen' in st.session_state and len(st.session_state['unseen']) > 0:
st.subheader("🧨 Want Spoilers?")
spoil_choice = st.selectbox("Choose one for a spoiler:", st.session_state['unseen'])
if st.button("🀐 Show Spoiler"):
spoiler_prompt = f"Give a short and juicy spoiler for the anime/manga '{spoil_choice}' without giving away everything."
spoiler = chat_with_groq(spoiler_prompt)
st.markdown(f"πŸ’£ **Spoiler for {spoil_choice}**: {spoiler}")