AllenNLP
File size: 1,154 Bytes
e68205d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import streamlit as st
from dotenv import load_dotenv
from groq import Groq

# Load environment variables from .env file
load_dotenv()

# Get the GROQ API Key from the environment
api_key = os.getenv("GROQ_API_KEY")

# If the API key is not found, show an error in the app
if not api_key:
    st.error("Please set the GROQ_API_KEY in the .env file.")
    st.stop()

# Initialize the Groq client with the API key
client = Groq(api_key=api_key)

# Streamlit app UI
st.title("GROQ API with Llama-3.3 Integration")
st.write("This app uses GROQ API to interact with Llama-3.3 for generating responses based on the user input.")

# User input section
user_input = st.text_area("Ask me anything about fast language models:")

if st.button("Generate Response"):
    if user_input:
        # Make API call to GROQ
        chat_completion = client.chat.completions.create(
            messages=[{"role": "user", "content": user_input}],
            model="llama-3.3-70b-versatile",
        )
        # Display the response from the model
        st.write(chat_completion.choices[0].message.content)
    else:
        st.error("Please enter a question.")