Creating a Simple AI App using Hugging Face Spaces
Lab Workbook: Creating a Simple AI Chatbot with Hugging Face Spaces
Introduction to Hugging Face Spaces
Lab instruction set with updates to ensure compatibility with the current GitHub authentication mechanisms.
Creating a Simple AI Chatbot with Hugging Face Spaces
## Introduction to Hugging Face Spaces
Hugging Face Spaces is a platform that allows developers to easily host and share machine learning models and applications. It provides a simple way to deploy AI models and create interactive demos without needing to set up the infrastructure. This is the concept of Serverless PaaS (Platform As A Service).
In this lab, we'll create a simple chatbot using a pre-trained language model and deploy it on Hugging Face Spaces.
Setting Up
Step 1: Create a Hugging Face Account
1. Go to [Hugging Face](https://huggingface.co/).
2. Click "Sign Up" and follow the prompts to create an account.
Step 2: Set Up a GitHub Account (if you don't have one)
1. Go to [GitHub](https://github.com/).
2. Click "Sign up" and follow the prompts to create an account.
Step 3: Install Git on Your Local Machine
1. Download and install Git from [Git-SCM](https://git-scm.com/downloads).
Step 4: Configure Git with Your GitHub Credentials
1. Go to [GitHub New Repository](https://github.com/new).
2. Name your repository "simple-chatbot".
3. Choose "Public" and initialize with a README.
4. Click "Create repository".
Step 2: Clone the Repository to Your Local Machine
```bash
git clone https://github.com/your-username/simple-chatbot.git
cd simple-chatbot
```
Step 3: Create the Necessary Files for Your Chatbot
**app.py:**
```python
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "microsoft/DialoGPT-small"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
1. Go to [Hugging Face Spaces](https://huggingface.co/spaces).
2. Click "Create new Space".
3. Choose a name for your Space (e.g., "simple-chatbot").
4. Select "Gradio" as the SDK.
5. Choose "Public" visibility.
6. Click "Create Space".
### Step 2: Link Your GitHub Repository
1. In your new Space, go to the "Files" tab.
2. Click on "Add file" and select "Repository".
3. Choose your GitHub account and select the "simple-chatbot" repository.
4. Click "Link repository".
Your application will now be automatically deployed to Hugging Face Spaces. You can view it by clicking on the "App" tab in your Space.
## Testing Your Chatbot
### Step 1: Interact with Your Chatbot
1. Go to the "App" tab in your Hugging Face Space.
2. Type a message in the input box and press Enter.
3. Observe the chatbot's response.
### Step 2: Share Your Chatbot
1. Copy the URL of your Space (e.g., `https://huggingface.co/spaces/your-username/simple-chatbot`).
2. Share this URL with others so they can interact with your chatbot.
## Creating a Python Client
### Create a New File Called `client.py` in Your Local Repository
This lab workbook provides a comprehensive guide to creating a simple AI chatbot using Hugging Face Spaces, from setup to deployment and testing. Students can follow these steps independently to create their own functional AI application.
Want to print your doc? This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (