import requests def get_groq_response(prompt, api_key): url = "https://api.groq.com/inference" # Replace with actual Groq API endpoint headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"} data = {"input": prompt} response = requests.post(url, headers=headers, json=data) if response.status_code == 200: return response.json().get("output", "No response") else: return f"Error: {response.status_code}, {response.text}" import streamlit as st st.title("Groq API Chatbot") api_key = st.text_input("Enter Groq API Key", type="password") if "conversation" not in st.session_state: st.session_state.conversation = [] user_input = st.text_input("You: ", "") if st.button("Send"): if user_input and api_key: st.session_state.conversation.append(f"You: {user_input}") # Get the response from Groq API response = get_groq_response(user_input, api_key) st.session_state.conversation.append(f"Bot: {response}") # Display the conversation history for message in st.session_state.conversation: st.write(message)