mashe commited on
Commit
c832f76
·
1 Parent(s): de94a3e
Files changed (3) hide show
  1. Dockerfile +27 -0
  2. app.py +31 -0
  3. requirements.txt +2 -0
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.9
3
+
4
+ # Install CUDA for GPU support (optional, based on your needs)
5
+ # Uncomment the following lines if you need GPU support
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ cuda-cudart-dev-11.0 \
8
+ && \
9
+ rm -rf /var/lib/apt/lists/*
10
+
11
+ # Set the working directory in the container
12
+ WORKDIR /app
13
+
14
+ # Copy the current directory contents into the container at /app
15
+ COPY . /app
16
+
17
+ # Install any needed packages specified in requirements.txt
18
+ RUN pip install --no-cache-dir -r requirements.txt
19
+
20
+ # Make port 7860 available to the world outside this container
21
+ EXPOSE 7860
22
+
23
+ # Define environment variable for Gradio server port
24
+ ENV GRADIO_SERVER_PORT=7860
25
+
26
+ # Run app.py when the container launches
27
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Initialize the StarCoder model
5
+ # Replace 'models/bigcode/starcoder' with the actual model path if different
6
+ code_generator = pipeline('text-generation', model='models/bigcode/starcoder')
7
+
8
+ def generate_code(prompt):
9
+ """
10
+ Generates code based on the given prompt.
11
+
12
+ Parameters:
13
+ - prompt (str): The input text to generate code from.
14
+
15
+ Returns:
16
+ - str: The generated code.
17
+ """
18
+ generated_code = code_generator(prompt, max_length=100, do_sample=True, temperature=0.7)
19
+ return generated_code[0]['generated_text']
20
+
21
+ # Create the Gradio interface
22
+ iface = gr.Interface(
23
+ fn=generate_code,
24
+ inputs=gr.Textbox(lines=5, label="Input Text"),
25
+ outputs=gr.Textbox(label="Generated Code"),
26
+ title="StarCoder Code Generator",
27
+ description="Enter a prompt to generate code using the StarCoder model.",
28
+ )
29
+
30
+ # Launch the Gradio interface
31
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ transformers