Thibault Goehringer commited on
Commit
1ef8a31
1 Parent(s): dee3e1a

Base files

Browse files
Files changed (4) hide show
  1. Dockerfile +19 -0
  2. README.md +1 -0
  3. main.py +25 -0
  4. requirements.txrt +5 -0
Dockerfile ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ # Get secret openai_api_token and output it to /test at buildtime
12
+ RUN --mount=type=secret,id=openai_api_token,mode=0444,required=true \
13
+ cat /run/secrets/openai_api_token > /test
14
+
15
+ # Get secret openai_api_token and clone it as repo at buildtime
16
+ RUN --mount=type=secret,id=openai_api_token,mode=0444,required=true \
17
+ git clone $(cat /run/secrets/openai_api_token)
18
+
19
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -5,6 +5,7 @@ colorFrom: green
5
  colorTo: green
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
5
  colorTo: green
6
  sdk: docker
7
  pinned: false
8
+ app_port: 7860
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
main.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+
3
+ openai.api_key = os.environ.get("openai_api_key")
4
+
5
+
6
+ _tweet = "I'm a pretty average middle aged guy, got a solid job and had a good family but things got messy and took " \
7
+ "a turn for the worst. Everyone says you need to hit rock bottom to go back up so here I am!"
8
+
9
+
10
+ def prompt(tweet, roast=True):
11
+ roast_or_toast = "snarky joke" if roast else "encouragement"
12
+ return f"A user tweeted this tweet:\n\n{tweet}\\n\nThe following {roast_or_toast} was given as an answer:"
13
+
14
+
15
+ response = openai.Completion.create(
16
+ engine="text-davinci-002",
17
+ prompt=prompt(_tweet, roast=False),
18
+ temperature=0.7,
19
+ max_tokens=60,
20
+ top_p=1,
21
+ frequency_penalty=0,
22
+ presence_penalty=0
23
+ )
24
+
25
+ print(response.choices[0].text.strip())
requirements.txrt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ sentencepiece==0.1.*
4
+ uvicorn[standard]==0.17.*
5
+ openai