|
--- |
|
title: Distilbert Base Uncased |
|
emoji: 🐠 |
|
colorFrom: yellow |
|
colorTo: gray |
|
sdk: streamlit |
|
sdk_version: 1.41.1 |
|
app_file: app.py |
|
pinned: true |
|
license: mit |
|
thumbnail: >- |
|
/static-proxy?url=https%3A%2F%2Fcdn-uploads.huggingface.co%2Fproduction%2Fuploads%2F64fbe312dcc5ce730e763dc6%2FIi2w5OVuSGhtPwC76W83c.png%3C%2Fspan%3E%3C!-- HTML_TAG_END --> |
|
--- |
|
|
|
To deploy your project on Streamlit, you'll need to create two essential files: `app.py` and `requirements.txt`. |
|
|
|
**1. `app.py`** |
|
|
|
This Python script serves as the main entry point for your Streamlit application. It should include the necessary imports and define the application's layout and functionality. Here's an example based on your project: |
|
|
|
```python |
|
import streamlit as st |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
import torch |
|
|
|
# Load the tokenizer and models |
|
tokenizer = AutoTokenizer.from_pretrained("cssupport/t5-small-awesome-text-to-sql") |
|
original_model = AutoModelForSeq2SeqLM.from_pretrained("cssupport/t5-small-awesome-text-to-sql", torch_dtype=torch.bfloat16) |
|
ft_model = AutoModelForSeq2SeqLM.from_pretrained("daljeetsingh/sql_ft_t5small_kag", torch_dtype=torch.bfloat16) |
|
|
|
# Move models to GPU |
|
device = 'cuda' if torch.cuda.is_available() else 'cpu' |
|
original_model.to(device) |
|
ft_model.to(device) |
|
|
|
# Streamlit app layout |
|
st.title("SQL Generation with T5 Models") |
|
|
|
# Input text box |
|
input_text = st.text_area("Enter your query:", height=150) |
|
|
|
# Generate button |
|
if st.button("Generate SQL"): |
|
if input_text: |
|
# Tokenize input |
|
inputs = tokenizer(input_text, return_tensors='pt').to(device) |
|
|
|
# Generate SQL queries |
|
with torch.no_grad(): |
|
original_sql = tokenizer.decode( |
|
original_model.generate(inputs["input_ids"], max_new_tokens=200)[0], |
|
skip_special_tokens=True |
|
) |
|
ft_sql = tokenizer.decode( |
|
ft_model.generate(inputs["input_ids"], max_new_tokens=200)[0], |
|
skip_special_tokens=True |
|
) |
|
|
|
# Display results |
|
st.subheader("Original Model Output") |
|
st.write(original_sql) |
|
st.subheader("Fine-Tuned Model Output") |
|
st.write(ft_sql) |
|
else: |
|
st.warning("Please enter a query to generate SQL.") |
|
``` |
|
|
|
**2. `requirements.txt`** |
|
|
|
This file lists all the Python packages your application depends on. Streamlit will use this file to install the necessary packages during deployment. Here's an example: |
|
|
|
``` |
|
streamlit |
|
transformers |
|
torch |
|
``` |
|
|
|
Ensure that the versions of the packages are compatible with each other and with your code. You can specify exact versions if needed, for example: |
|
|
|
``` |
|
streamlit==1.15.2 |
|
transformers==4.11.3 |
|
torch==1.10.0 |
|
``` |
|
|
|
To generate a `requirements.txt` file with the exact versions of the packages installed in your environment, you can use the following command: |
|
|
|
``` |
|
pip freeze > requirements.txt |
|
``` |
|
|
|
This command will list all installed packages and their versions, which you can then include in your `requirements.txt` file. |
|
|
|
For more information on creating and deploying Streamlit apps, refer to the official Streamlit documentation: |
|
|
|
- [Create an app](https://docs.streamlit.io/get-started/tutorials/create-an-app) |
|
|
|
- [App dependencies for your Community Cloud app](https://docs.streamlit.io/deploy/streamlit-community-cloud/deploy-your-app/app-dependencies) |
|
|
|
By setting up these files correctly, you can deploy your SQL generation application on Streamlit, allowing users to input queries and receive generated SQL statements from both the original and fine-tuned models. |