SUHAN-I commited on
Commit
e58a576
·
verified ·
1 Parent(s): b2d67f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py CHANGED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries
2
+ import os
3
+ import streamlit as st
4
+ import pandas as pd
5
+ from groq import Groq
6
+ from PIL import Image
7
+ from io import BytesIO
8
+ import requests
9
+ from streamlit_lottie import st_lottie # Import streamlit-lottie
10
+
11
+ # Setup environment variables (set your API keys here)
12
+ os.environ["GROQ_API_KEY"] = "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"
13
+
14
+ # Initialize Groq client
15
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
16
+
17
+ # Load dataset once using caching
18
+ @st.cache_data
19
+ def load_data():
20
+ # Load the CSV file only once
21
+ data = pd.read_csv('/content/movie_dataset.csv') # Replace with the actual file name
22
+ return data
23
+
24
+ # Load Groq model for chat completion
25
+ def get_groq_completion(query, model="gemma2-9b-it"):
26
+ chat_completion = client.chat.completions.create(
27
+ messages=[
28
+ {
29
+ "role": "user",
30
+ "content": query,
31
+ }
32
+ ],
33
+ model=model,
34
+ )
35
+ return chat_completion.choices[0].message.content
36
+
37
+ # Function to load Lottie animations
38
+ def load_lottie_url(url: str):
39
+ r = requests.get(url)
40
+ if r.status_code != 200:
41
+ return None
42
+ return r.json()
43
+
44
+ # Define Streamlit app
45
+ def main():
46
+ # Page Configuration
47
+ st.set_page_config(page_title="Movie RAG Chatbot", page_icon="🎥", layout="wide", initial_sidebar_state="expanded")
48
+
49
+ # Apply CSS styling for dark theme and animations
50
+ st.markdown("""
51
+ <style>
52
+ body {background-color: #1f1f1f; color: #f5f5f5;}
53
+ .stButton>button {background-color: #f5a623; color: white;}
54
+ .stTextInput>div>div>input {background-color: #333; color: #f5f5f5;}
55
+ h1 {color: #f5a623; text-align: center;}
56
+ </style>
57
+ """, unsafe_allow_html=True)
58
+
59
+ st.title("🎬 Movie RAG Chatbot")
60
+
61
+ # Load the dataset only once
62
+ data = load_data()
63
+ st.write("### Dataset Overview", data.head())
64
+
65
+ # Load Lottie animation
66
+ lottie_animation_url = "https://assets5.lottiefiles.com/packages/lf20_OZ6W7g.json" # Replace with your desired Lottie URL
67
+ lottie_json = load_lottie_url(lottie_animation_url)
68
+ if lottie_json:
69
+ st_lottie(lottie_json, speed=1, width=None, height=None, key="loading")
70
+
71
+ # Query input
72
+ user_query = st.text_input("Ask about movies or actors:", placeholder="e.g., Tell me about sci-fi movies.")
73
+
74
+ if st.button("Get Response"):
75
+ # Fetch info from RAG model
76
+ groq_response = get_groq_completion(user_query)
77
+
78
+ st.write("### Chatbot Response")
79
+ st.markdown(f"Groq Model: {groq_response}")