Spaces:
Sleeping
Sleeping
File size: 1,706 Bytes
73b3250 6bd0088 73b3250 b67aee1 e867839 b67aee1 e867839 b67aee1 86eac15 e867839 b67aee1 73b3250 e867839 73b3250 b67aee1 e867839 b67aee1 73b3250 b67aee1 73b3250 86eac15 73b3250 b67aee1 73b3250 6bd0088 86eac15 |
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 44 45 46 47 48 49 50 |
import os
import gradio as gr
from groq import Groq
import traceback
import logging
# Setup logging
logging.basicConfig(filename="error.log", level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
# Check if API key is loaded
api_key = os.environ.get("GROQ_API_KEY")
if not api_key:
logging.error("Missing GROQ_API_KEY environment variable.")
client = Groq(api_key=api_key)
# Function with error logging
def chat_inference(message, history, example_prompt):
try:
logging.debug(f"User message: {message}")
response = client.chat.completions.create(
messages=[{"role": "user", "content": message}],
model="compound-beta"
)
reply = response.choices[0].message.content
logging.debug(f"Groq reply: {reply}")
except Exception as e:
error_details = traceback.format_exc()
logging.error(f"Error during Groq API call:\n{error_details}")
reply = f"⚠️ Error: Connection error or API issue.\n\nSee logs in `error.log` for more info."
return reply
# Optional input
additional_inputs = [
gr.Textbox(label="🔍 Example Prompt", value="What were the main highlights from the latest Apple keynote?")
]
chat_interface = gr.ChatInterface(
fn=chat_inference,
additional_inputs=additional_inputs,
additional_inputs_accordion=gr.Accordion("⚙️ Configuration & Advanced Parameters", open=True),
title="🔍 AI-Powered Real-Time Search with Groq",
description="Ask anything that requires real-time info — powered by Groq’s `compound-beta` model.",
theme="default",
type="messages", # Correct format
)
if __name__ == "__main__":
chat_interface.launch()
|