devi1675's picture
Create app.py
ed145bb verified
Raw History Blame Contribute Delete
1.8 kB
from openai import OpenAI
import gradio as gr
from dotenv import load_dotenv
import os
load_dotenv()
base_url = "https://generativelanguage.googleapis.com/v1beta/openai/"
api_key = os.getenv("GOOGLE_API_KEY")
client = OpenAI(base_url=base_url, api_key=api_key)
model = "gemini-2.5-flash-lite"
Customer_Support_Chatbot = """A customer support chatbot acts as a virtual assistant designed to help users with their queries, complaints, and requests in real time. It can answer frequently asked questions, provide troubleshooting steps, track orders, and even escalate complex issues to a human agent when necessary. Unlike traditional support systems, a chatbot is available 24/7, ensuring that users can get instant help anytime. Its role is to improve customer experience by giving quick, accurate, and consistent responses, while also reducing the workload of human support staff."""
def get_response(message, history):
messages = [{"role": "system", "content": Customer_Support_Chatbot}]
messages.extend(history)
messages.append({"role": "user", "content": message})
response = client.chat.completions.create(model=model, messages=messages)
ai_response = response.choices[0].message.content
return ai_response
PAGE_TITLE = "CUSTOMER SUPPORT CHATBOT!"
ASSISTANT_AVATAR_URL = "https://raw.githubusercontent.com/hereandnowai/images/refs/heads/main/logos/caramel-face.jpeg"
description_md = f"""<br>im your ai who gives customer support"""
gr.ChatInterface(
fn=get_response,
chatbot=gr.Chatbot(type="messages", avatar_images=[None, ASSISTANT_AVATAR_URL]),
title=PAGE_TITLE,
description=description_md,
examples=["where is my order?","what is your return policy?","my product is not working"],
type="messages"
).queue().launch(show_error=True, ssr_mode=False)