by we

First ever gradio template

Test this app for free
27
import logging
import gradio as gr
from flask import Flask, render_template, session, request, jsonify
from flask_session import Session
from gunicorn.app.base import BaseApplication
from abilities import llm

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

app = Flask(__name__)
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)

def chatbot(message, history, model, temperature):
    conversation_history = " ".join([f"user: {h[0]} bot: {h[1]}" for h in history])
    conversation_history += f" user: {message}"
    
    response = llm(
        prompt=conversation_history,
        response_schema={
            "type": "object",
            "properties": {
Get full code

Created: | Last Updated:

First ever gradio template

Here's a step-by-step guide on how to use the provided Gradio chatbot template:

Introduction to the Template

This template provides a customizable chatbot interface using Gradio, Flask, and various AI models. It allows users to interact with different language models through a simple web interface.

Getting Started

  1. Click "Start with this Template" to begin using the chatbot template in the Lazy Builder interface.

Test the Application

  1. Press the "Test" button to deploy the application and launch the Lazy CLI.

Using the Chatbot

  1. Once the application is deployed, you'll receive a dedicated server link to access the chatbot interface.

  2. Open the provided link in your web browser to interact with the chatbot.

  3. The chatbot interface includes the following elements:

  4. A chat window displaying the conversation history
  5. A text input box for entering your messages
  6. A dropdown menu to select the AI model
  7. A temperature slider to adjust the model's creativity

  8. To use the chatbot:

  9. Type your message in the text input box
  10. Select an AI model from the dropdown menu (options include gpt-4o, gpt-4o-mini, claude-3-5-sonnet, claude-3-haiku, and deepseek/deepseek-coder)
  11. Adjust the temperature slider if desired (higher values increase randomness)
  12. Press Enter or click the submit button to send your message

  13. The chatbot will process your input and generate a response based on the selected model and settings.

  14. Continue the conversation by sending additional messages and receiving responses from the AI.

Customizing the Chatbot

The template allows for easy customization:

  • To add or remove AI models, modify the model dropdown options in the launch() function.
  • To adjust the temperature range, modify the temperature slider parameters in the launch() function.
  • To change the chatbot's behavior or add new features, you can modify the chatbot() function in the code.

Remember that all changes and deployments are handled through the Lazy platform, so you don't need to worry about setting up a local environment or managing dependencies.

Technologies

Optimize AWS Workflows with Lazy AI: Automate Deployments, Scaling, Monitoring and More Optimize AWS Workflows with Lazy AI: Automate Deployments, Scaling, Monitoring and More

Similar templates