GrokChatBuddy / app.py
yasserrmd's picture
Create app.py
b640d2d verified
raw
history blame
1.52 kB
import os
import openai
import gradio as gr
# Initialize OpenAI client with Groq model
XAI_API_KEY = os.getenv("XAI_API_KEY")
openai.api_key = XAI_API_KEY
# Define a function to handle chat with humor
def chat_with_buddy(user_message):
try:
# Generate a response from Groq with a humorous twist
response = openai.ChatCompletion.create(
model="grok-beta",
messages=[
{"role": "system", "content": "You are Chat Buddy, a friendly and humorous chatbot who loves to make people smile."},
{"role": "user", "content": user_message},
]
)
# Extract and return the response content with a hint of humor
reply = response.choices[0].message["content"]
# Add a humorous touch to the response
if not reply.endswith("πŸ˜„"):
reply += " πŸ˜„" # Ensure a smile at the end of each response
return reply
except Exception as e:
return f"Oops, something went wrong! Just blame it on the robots... πŸ˜‰ (Error: {str(e)})"
# Set up the Gradio interface
interface = gr.Interface(
fn=chat_with_buddy, # Function to call
inputs="text", # Input type
outputs="text", # Output type
title="Chat Buddy", # Title for the interface
description="Your friendly chatbot with a touch of humor! Ask Chat Buddy anything, and enjoy a chat that’s both helpful and light-hearted."
)
# Launch the app
interface.launch()