zhuchi76 commited on
Commit
6d7d459
·
1 Parent(s): 6324ee2

feat: add GitHub Actions workflow and Docker setup

Browse files

- Add GitHub Actions workflow for syncing to Hugging Face hub
- Create Dockerfile with PyTorch and CUDA support
- Implement Streamlit app for text-to-image generation
- Add requirements.txt for dependencies

Files changed (4) hide show
  1. .github/workflows/main.yml +23 -0
  2. Dockerfile +35 -0
  3. app.py +32 -0
  4. requirements.txt +9 -0
.github/workflows/main.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ with:
15
+ fetch-depth: 0
16
+ - name: Add remote
17
+ env:
18
+ HF: ${{ secrets.HF }}
19
+ run: git remote add space https://argnctu:[email protected]/spaces/argnctu/text-to-image
20
+ - name: Push to hub
21
+ env:
22
+ HF: ${{ secrets.HF }}
23
+ run: git push --force https://argnctu:[email protected]/spaces/argnctu/text-to-image main
Dockerfile ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Base image with PyTorch and CUDA support
2
+ FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04
3
+
4
+ # Set environment variables
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+ ENV PYTHONDONTWRITEBYTECODE=1
7
+ ENV PYTHONUNBUFFERED=1
8
+
9
+ # Install essential packages
10
+ RUN apt-get update && apt-get install -y --no-install-recommends \
11
+ python3.8 \
12
+ python3-pip \
13
+ python3-venv \
14
+ git \
15
+ wget \
16
+ libgl1-mesa-glx \
17
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
18
+
19
+ # Set Python aliases
20
+ RUN ln -s /usr/bin/python3.8 /usr/bin/python && \
21
+ ln -s /usr/bin/pip3 /usr/bin/pip
22
+
23
+ RUN useradd -m -u 1000 user
24
+ USER user
25
+ ENV PATH="/home/user/.local/bin:$PATH"
26
+
27
+ WORKDIR /app
28
+
29
+ COPY --chown=user ./requirements.txt requirements.txt
30
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
31
+
32
+ COPY --chown=user . /app
33
+ EXPOSE 7860
34
+
35
+ CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ from flux import FLUXModel # Assuming FLUX.1-dev provides this
4
+
5
+ # Initialize the FLUX model (load only once)
6
+ @st.cache_resource
7
+ def load_model():
8
+ return FLUXModel.from_pretrained("flux-1-dev")
9
+
10
+ model = load_model()
11
+
12
+ # Streamlit GUI
13
+ st.title("Text-to-Image Generator with FLUX.1-dev")
14
+ st.subheader("Enter a prompt to generate stunning images!")
15
+
16
+ # Text input
17
+ prompt = st.text_input("Enter your prompt", "")
18
+
19
+ # Generate image when button is clicked
20
+ if st.button("Generate Image"):
21
+ if prompt:
22
+ with st.spinner("Generating image... Please wait."):
23
+ try:
24
+ image = model.generate_image(prompt) # Generate image
25
+ st.image(image, caption="Generated Image", use_column_width=True)
26
+ except Exception as e:
27
+ st.error(f"Error generating image: {e}")
28
+ else:
29
+ st.warning("Please enter a prompt!")
30
+
31
+ # Footer
32
+ st.write("Powered by FLUX.1-dev and Streamlit")
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ torch>=2.0.0
2
+ transformers>=4.28.0
3
+ diffusers>=0.15.0
4
+ accelerate>=0.19.0
5
+ pillow
6
+ numpy
7
+ scipy
8
+ flux-1-dev
9
+ streamlit