Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
from groq import Groq | |
from dotenv import load_dotenv | |
# Load environment variables from .env file | |
load_dotenv() | |
# Title of the app | |
st.title("Simple AI Agent with LLaMA 3.1") | |
# Description | |
st.markdown("This is an AI agent powered by the LLaMA 3.1 model and Groq API.") | |
# Input for user queries | |
user_input = st.text_input("Ask something:") | |
# Display response area | |
if st.button("Get Response"): | |
# Fetch API key from .env file | |
api_key = os.getenv("GROQ_API_KEY") | |
if api_key and user_input: | |
# Set up Groq client | |
client = Groq(api_key=api_key) | |
try: | |
# Send query to LLaMA model | |
chat_completion = client.chat.completions.create( | |
messages=[{"role": "user", "content": user_input}], | |
model="llama3-8b-8192", | |
) | |
# Display response | |
st.success(chat_completion.choices[0].message.content) | |
except Exception as e: | |
st.error(f"Error: {e}") | |
else: | |
st.warning("Please ensure the API key is set in the .env file and ask a valid question.") | |