Spaces:
Runtime error
Runtime error
Initial Space setup of broadfield-dev/my-ai-space2 via Builder
Browse files- Dockerfile +20 -0
- app.py +22 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
### Base image for Hugging Face transformer models
|
2 |
+
FROM huggingface/transformers:4.10.2
|
3 |
+
|
4 |
+
### Set the working directory to /app
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
### Copy the requirements.txt file
|
8 |
+
COPY requirements.txt .
|
9 |
+
|
10 |
+
### Install the dependencies
|
11 |
+
RUN pip install -r requirements.txt
|
12 |
+
|
13 |
+
### Collect static files
|
14 |
+
COPY . .
|
15 |
+
|
16 |
+
### Make port 8000 available to the world
|
17 |
+
EXPOSE 8000
|
18 |
+
|
19 |
+
### Run the Gradio app
|
20 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
4 |
+
|
5 |
+
def generate_text(prompt, length):
|
6 |
+
model_name = "EleutherAI/gpt-neo-1.3B"
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
10 |
+
output = model.generate(**inputs, max_length=length, num_beams=4, early_stopping=True)
|
11 |
+
return tokenizer.decode(output[0], skip_special_tokens=True)
|
12 |
+
|
13 |
+
demo = gr.Interface(
|
14 |
+
fn=generate_text,
|
15 |
+
inputs=["text", "int"],
|
16 |
+
outputs="text",
|
17 |
+
title="Hugging Face Text Generation",
|
18 |
+
description="Enter a prompt and a length, and this chatbot will generate text using a pre-trained GPT-Neo model."
|
19 |
+
)
|
20 |
+
|
21 |
+
if __name__ == "__main__":
|
22 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
gradio
|