File size: 1,281 Bytes
ce6080c
25a9cec
ce6080c
25a9cec
ce6080c
e09acd2
25a9cec
ce6080c
1a235f5
 
25a9cec
e09acd2
 
 
25a9cec
e09acd2
 
 
3f247af
e09acd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
import os
from dotenv import load_dotenv
from groq import Groq
import streamlit as st

# Load environment variables
load_dotenv()

GROQ_API_KEY = "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"
client = Groq(api_key =GROQ_API_KEY)

# Streamlit UI
st.title("Python Bot with Groq's API")
st.subheader("Interact with an AI Model Powered by Groq")

# Input Section
st.header("Input")
user_input = st.text_input("Enter your question or message below:")

# Submit button
if st.button("Submit"):
    if user_input.strip():
        # Output Section
        st.header("Output")
        with st.spinner("Fetching response from the LLM..."):
            try:
                # Interact with Groq's LLM
                chat_completion = client.chat.completions.create(
                    messages=[
                        {"role": "user", "content": user_input},
                    ],
                    model="llama3-8b-8192",
                    stream=False,
                )
                response = chat_completion.choices[0].message.content
                st.success("Here is the AI's response:")
                st.write(response)
            except Exception as e:
                st.error(f"Error: {e}")
    else:
        st.warning("Please enter a valid message!")