Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from groq import Groq
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
# Load API key from .env file
|
| 7 |
+
load_dotenv()
|
| 8 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 9 |
+
|
| 10 |
+
# Ensure API key is set
|
| 11 |
+
if not GROQ_API_KEY:
|
| 12 |
+
st.error("API key is missing. Please check your .env file.")
|
| 13 |
+
st.stop()
|
| 14 |
+
|
| 15 |
+
# Initialize Groq API Client with API Key
|
| 16 |
+
client = Groq(api_key=GROQ_API_KEY)
|
| 17 |
+
|
| 18 |
+
# Streamlit UI
|
| 19 |
+
st.set_page_config(page_title="💄 Makeup & Cosmetics Assistant", layout="wide")
|
| 20 |
+
st.title("💄 Makeup & Cosmetics Assistant")
|
| 21 |
+
st.write("Ask anything about makeup brands, beauty tips, and skincare!")
|
| 22 |
+
|
| 23 |
+
# User input
|
| 24 |
+
user_query = st.text_input("Enter your question:", "")
|
| 25 |
+
|
| 26 |
+
if st.button("Ask"):
|
| 27 |
+
if user_query.strip():
|
| 28 |
+
with st.spinner("Fetching response..."):
|
| 29 |
+
# Query the DeepSeek model
|
| 30 |
+
completion = client.chat.completions.create(
|
| 31 |
+
model="deepseek-r1-distill-qwen-32b",
|
| 32 |
+
messages=[{"role": "user", "content": user_query}],
|
| 33 |
+
temperature=0.6,
|
| 34 |
+
max_completion_tokens=4096,
|
| 35 |
+
top_p=0.95,
|
| 36 |
+
stream=True,
|
| 37 |
+
stop=None,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Display response
|
| 41 |
+
response_text = ""
|
| 42 |
+
for chunk in completion:
|
| 43 |
+
response_text += chunk.choices[0].delta.content or ""
|
| 44 |
+
|
| 45 |
+
st.write("**💡 Answer:**")
|
| 46 |
+
st.write(response_text)
|
| 47 |
+
else:
|
| 48 |
+
st.warning("Please enter a valid question related to makeup and cosmetics!")
|
| 49 |
+
|
| 50 |
+
# Footer
|
| 51 |
+
st.markdown("---")
|
| 52 |
+
st.markdown("🔹 **Powered by DeepSeek-R1-Distill-Qwen-32B & Groq API**")
|