Spaces:
Running
Running
File size: 1,524 Bytes
b640d2d |
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 |
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()
|