import os from langchain.prompts import PromptTemplate from langchain.llms import OpenAI import gradio as gr import random import time from gradio_client import Client os.environ["OPENAI_API_KEY"] = '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' def get_response(query, history, llm): client = Client("https://traversaal-fitx-ai.hf.space/") result = client.predict( query, # str in 'query' Textbox component history, # str in 'history' Textbox component api_name="/predict" ) return result llm = prepare_resources() custom_css = """ """ def respond(message, chat_history): if not chat_history: # Display a welcome message if chat_history is empty welcome_message = "Welcome to the AI Trainer Chatbot! I'm here to assist you with your questions." chat_history = [(welcome_message, get_response(welcome_message, chat_history, llm))] bot_message = get_response(message, chat_history, llm) chat_history.append(bot_message) time.sleep(0.5) return "", chat_history # Display the welcome message before creating the Gradio interface welcome_message = "Welcome to the AI Trainer Chatbot! I'm here to assist you with your questions." print(welcome_message) with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo: chatbot_title = gr.HTML('
AI Trainer Chatbot
') chatbot = gr.Chatbot() msg = gr.Textbox(placeholder="I am your personal AI Trainer. Ask me a question") msg.submit(respond, [msg, chatbot], [msg, chatbot]) demo.launch(debug=True)