Skip to main content

Goals

  • Build your own AI agent using Friendli Model APIs and Gradio in less than 50 LoC
  • Share your AI agent with the world and gather feedback
Gradio is the fastest way to demo your model with a friendly web interface.

Getting Started

  1. Head to Friendli Suite, and create an account.
  2. Grab a Personal API Key to use Friendli Model APIs within an agent.

Step 1. Prerequisite

Install dependencies.
pip install openai gradio

Step 2. Launch Your Agent

Build your own AI agent using Friendli Model APIs and Gradio.
  • Gradio provides a ChatInterface that implements a chatbot UI running the chat_function.
    • More information about the chat_function(message, history)
      The input function should accept two parameters: a string input message and list of two-element lists of the form [[user_message, bot_message], …] representing the chat history, and return a string response.
  • Implement the chat_function using Friendli Model APIs.
from openai import OpenAI
import gradio as gr

friendli_client = OpenAI(
    base_url="https://api.friendli.ai/serverless/v1",
    api_key="YOUR_API_KEY"
)

def chat_function(message, history):
    messages = []
    for user, chatbot in history:
        messages.append({"role" : "user", "content": user})
        messages.append({"role" : "assistant", "content": chatbot})
    messages.append({"role": "user", "content": message})

    stream = friendli_client.chat.completions.create(
        model="zai-org/GLM-5.2",
        messages=messages,
        stream=True
    )
    res = ""
    for chunk in stream:
        res += chunk.choices[0].delta.content or ""
        yield res

css = """
.gradio-container {
    max-width: 800px !important;
    margin-top: 100px !important;
}

.pending {
    display: none !important;
}

.sm {
    box-shadow: None !important;
}

#component-2 {
    height: 400px !important;
}
"""

with gr.Blocks(theme=gr.themes.Soft(), css=css) as friendli_agent:
    gr.ChatInterface(chat_function)

friendli_agent.launch()

Step 3. Deploy Your Agent

For the temporary deployment, change the last line of the code.
friendli_agent.launch(share=True)
For the permanent deployment, you can use Hugging Face Spaces!
Last modified on July 6, 2026