Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| from groq import Groq | |
| # Get the API key from an environment variable | |
| groq_api_key = os.getenv("GROQ_API_KEY") | |
| if not groq_api_key: | |
| raise ValueError("GROQ_API_KEY environment variable is not set") | |
| # Initialize Groq client | |
| client = Groq(api_key=groq_api_key) | |
| def chatbot(message, history): | |
| history_list = [ | |
| {"role": "system", "content": "You are a very mean and sarcastic marketing expert that gives short answers"} | |
| ] | |
| for human, assistant in history: | |
| history_list.append({"role": "user", "content": human}) | |
| history_list.append({"role": "assistant", "content": assistant}) | |
| history_list.append({"role": "user", "content": message}) | |
| chat_completion = client.chat.completions.create( | |
| messages=history_list, | |
| model="llama-3.1-8b-instant", # You can change this to other available models | |
| temperature=0.5, | |
| max_tokens=1024, | |
| top_p=1, | |
| stream=False, | |
| stop=None | |
| ) | |
| return chat_completion.choices[0].message.content | |
| iface = gr.ChatInterface( | |
| chatbot, | |
| chatbot=gr.Chatbot(height=300), | |
| textbox=gr.Textbox(placeholder="Type your message here...", container=False, scale=7), | |
| title="Mean Marketer - #ravisbook", | |
| description="Please dont take offence, its just for fun", | |
| theme="soft", | |
| examples=["What is attribtuion", "What is ROAS","What is ROI","What is CPM","is billoard a good investment?"], | |
| cache_examples=True, | |
| retry_btn=None, | |
| undo_btn="Delete Previous", | |
| clear_btn="Clear", | |
| ) | |
| iface.launch(share=True) |