Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Initialize OpenAI client with Groq model
|
6 |
+
XAI_API_KEY = os.getenv("XAI_API_KEY")
|
7 |
+
openai.api_key = XAI_API_KEY
|
8 |
+
|
9 |
+
# Define a function to handle chat with humor
|
10 |
+
def chat_with_buddy(user_message):
|
11 |
+
try:
|
12 |
+
# Generate a response from Groq with a humorous twist
|
13 |
+
response = openai.ChatCompletion.create(
|
14 |
+
model="grok-beta",
|
15 |
+
messages=[
|
16 |
+
{"role": "system", "content": "You are Chat Buddy, a friendly and humorous chatbot who loves to make people smile."},
|
17 |
+
{"role": "user", "content": user_message},
|
18 |
+
]
|
19 |
+
)
|
20 |
+
# Extract and return the response content with a hint of humor
|
21 |
+
reply = response.choices[0].message["content"]
|
22 |
+
|
23 |
+
# Add a humorous touch to the response
|
24 |
+
if not reply.endswith("π"):
|
25 |
+
reply += " π" # Ensure a smile at the end of each response
|
26 |
+
return reply
|
27 |
+
|
28 |
+
except Exception as e:
|
29 |
+
return f"Oops, something went wrong! Just blame it on the robots... π (Error: {str(e)})"
|
30 |
+
|
31 |
+
# Set up the Gradio interface
|
32 |
+
interface = gr.Interface(
|
33 |
+
fn=chat_with_buddy, # Function to call
|
34 |
+
inputs="text", # Input type
|
35 |
+
outputs="text", # Output type
|
36 |
+
title="Chat Buddy", # Title for the interface
|
37 |
+
description="Your friendly chatbot with a touch of humor! Ask Chat Buddy anything, and enjoy a chat thatβs both helpful and light-hearted."
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the app
|
41 |
+
interface.launch()
|