Dua Rajper commited on
Commit
b047f7c
·
verified ·
1 Parent(s): 0d42199

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables from .env file
7
+ load_dotenv()
8
+
9
+ # Get API key from .env
10
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
11
+
12
+ # Streamlit UI
13
+ st.title("Hugging Face & GROQ API Chatbot")
14
+ st.write("Enter a message below to interact with the AI.")
15
+
16
+ # User input
17
+ user_input = st.text_area("Your Message", "Explain the importance of fast language models")
18
+
19
+ if st.button("Generate Response"):
20
+ if not GROQ_API_KEY:
21
+ st.error("API Key is missing. Please check your .env file.")
22
+ else:
23
+ try:
24
+ # Initialize GROQ client
25
+ client = Groq(api_key=GROQ_API_KEY)
26
+
27
+ # Generate response
28
+ chat_completion = client.chat.completions.create(
29
+ messages=[{"role": "user", "content": user_input}],
30
+ model="llama-3.3-70b-versatile",
31
+ )
32
+
33
+ # Display response
34
+ response = chat_completion.choices[0].message.content
35
+ st.write("### AI Response:")
36
+ st.write(response)
37
+
38
+ except Exception as e:
39
+ st.error(f"Error: {e}")