Spaces:
Sleeping
Sleeping
File size: 2,915 Bytes
f2b0747 d245f11 f2b0747 bb3dd8d f2b0747 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
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}")
|