|
import os |
|
from dotenv import load_dotenv |
|
from groq import Groq |
|
import streamlit as st |
|
|
|
|
|
load_dotenv() |
|
|
|
GROQ_API_KEY = "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" |
|
client = Groq(api_key =GROQ_API_KEY) |
|
|
|
|
|
st.title("Python Bot with Groq's API") |
|
st.subheader("Interact with an AI Model Powered by Groq") |
|
|
|
|
|
st.header("Input") |
|
user_input = st.text_input("Enter your question or message below:") |
|
|
|
|
|
if st.button("Submit"): |
|
if user_input.strip(): |
|
|
|
st.header("Output") |
|
with st.spinner("Fetching response from the LLM..."): |
|
try: |
|
|
|
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!") |