Spaces:
Sleeping
Sleeping
File size: 1,162 Bytes
48ce55c e28fac2 48ce55c e28fac2 48ce55c |
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 42 43 |
import os
from dotenv import load_dotenv
from groq import Groq
import streamlit as st
# Load environment variables
load_dotenv()
# Set Groq API Key
api_key = os.getenv("GROQ_API_KEY")
if not api_key:
raise ValueError("GROQ_API_KEY is not set in the environment.")
client = Groq(api_key=api_key)
# Function to generate response using Groq
def chat_with_llm(user_message, model="llama3-8b-8192"):
try:
# Send message to Groq LLM
chat_completion = client.chat.completions.create(
messages=[
{"role": "user", "content": user_message},
],
model=model,
)
# Return the LLM's response
return chat_completion.choices[0].message.content
except Exception as e:
return f"Error: {e}"
# Streamlit App
def main():
st.title("Real-Time Text-to-Text Chatbot")
user_input = st.text_input("You:", "")
if st.button("Send"):
if user_input.strip():
with st.spinner("Thinking..."):
bot_response = chat_with_llm(user_input)
st.text_area("Bot:", bot_response, height=150)
if __name__ == "__main__":
main()
|