|
import gradio as gr |
|
import requests |
|
|
|
|
|
def fastlane_agent(message, history): |
|
|
|
history_openai_format = [ |
|
{"role": "system", "content": "You are an assistant for an eCommerce store."}] |
|
for human, assistant in history: |
|
history_openai_format.append({"role": "user", "content": human}) |
|
history_openai_format.append( |
|
{"role": "assistant", "content": assistant}) |
|
history_openai_format.append({"role": "user", "content": message}) |
|
|
|
response = requests.post( |
|
"http://localhost:8000/query-handler/", json={"text": message, "history": history_openai_format}) |
|
if response.status_code == 200: |
|
return response.json().get("generative response") |
|
else: |
|
return "Error: Could not fetch response." |
|
|
|
|
|
iface = gr.ChatInterface( |
|
fn=fastlane_agent, |
|
chatbot=gr.Chatbot(height=400), |
|
textbox=gr.Textbox( |
|
placeholder="How can I help you?", container=False, scale=7 |
|
), |
|
title="Fastlane Chat GPT", |
|
description="AI sales assistance for e-commmerce", |
|
theme="soft", |
|
examples=["Hello", "What is the status of my order?", |
|
"Recommend me products"], |
|
cache_examples=True, |
|
retry_btn=None, |
|
undo_btn="Delete Previous", |
|
clear_btn="Clear" |
|
) |
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|