Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from groq import Groq
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
# Load environment variables from .env file
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Title of the app
|
10 |
+
st.title("Simple AI Agent with LLaMA 3.1")
|
11 |
+
|
12 |
+
# Description
|
13 |
+
st.markdown("This is an AI agent powered by the LLaMA 3.1 model and Groq API.")
|
14 |
+
|
15 |
+
# Input for user queries
|
16 |
+
user_input = st.text_input("Ask something:")
|
17 |
+
|
18 |
+
# Display response area
|
19 |
+
if st.button("Get Response"):
|
20 |
+
# Fetch API key from .env file
|
21 |
+
api_key = os.getenv("GROQ_API_KEY")
|
22 |
+
|
23 |
+
if api_key and user_input:
|
24 |
+
# Set up Groq client
|
25 |
+
client = Groq(api_key=api_key)
|
26 |
+
|
27 |
+
try:
|
28 |
+
# Send query to LLaMA model
|
29 |
+
chat_completion = client.chat.completions.create(
|
30 |
+
messages=[{"role": "user", "content": user_input}],
|
31 |
+
model="llama3-8b-8192",
|
32 |
+
)
|
33 |
+
# Display response
|
34 |
+
st.success(chat_completion.choices[0].message.content)
|
35 |
+
except Exception as e:
|
36 |
+
st.error(f"Error: {e}")
|
37 |
+
else:
|
38 |
+
st.warning("Please ensure the API key is set in the .env file and ask a valid question.")
|