Skip to content

Latest commit

 

History

History
62 lines (42 loc) · 2.47 KB

README.md

File metadata and controls

62 lines (42 loc) · 2.47 KB

Week 09 Mini Project - Streamlit App with a Hugging Face Model

This project involves creating a web application using Streamlit and integrating it with a Hugging Face large language model (LLM). The application allows users to generate text based on their input.

Project Requirements

  • Create a website using Streamlit
  • Connect to an open source LLM (Hugging Face)
  • Deploy model via Streamlit or other service (accessible via browser)

Project Implementation

This repository contains a Streamlit web application that uses a Hugging Face model to generate text based on user input. The application allows users to enter a text prompt and generate text based on that prompt using openAI's pre-trained language model, gpt2.

Steps to build a Streamlit app with a Hugging Face model

  1. Install necessary libraries: This project requires Streamlit and Transformers. You can install them using pip:
pip install streamlit transformers
  1. Create a new Python file for the web app: This will be your main app file. Let's call it app.py

  2. Import necessary libraries: You will need to import Streamlit and Transformers in your app.py file:

import streamlit as st
from transformers import pipeline
  1. Initialize the Hugging Face model: Use the pipeline function from the transformers library to load the model. For example, if you're using a text generation model:
generator = pipeline('text-generation', model='gpt2')
  1. Create Streamlit app: Use Streamlit's functions to create the interface for your app. For example, you can create a text input for the user to enter some text, and a button to generate text. Here's an example:
st.sidebar.title("Input Options")
input_text = st.sidebar.text_input("Enter some text")
generate_button = st.sidebar.button("Generate")
  1. Generate text based on user input: When the user clicks the "Generate" button, you can use the Hugging Face model to generate text based on the input. For example:
if generate_button:
    with st.spinner("Generating text..."):
        output_text = generator(input_text)[0]["generated_text"]
    st.subheader("Generated Text:")
    st.write(output_text)
  1. Run the Streamlit app: You can run the app using the following command:
streamlit run app.py
  1. Deploy the app: You can deploy the app using Streamlit's sharing service or other platforms like Heroku or AWS.