Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files- Dockerfile +20 -0
- app.py +25 -0
- requirements.txt +2 -0
- utils/summarizer.py +41 -0
- workcell.yaml +10 -0
Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.8
|
| 5 |
+
|
| 6 |
+
# Set up a new user named "user" with user ID 1000
|
| 7 |
+
RUN useradd -m -u 1000 user
|
| 8 |
+
# Switch to the "user" user
|
| 9 |
+
USER user
|
| 10 |
+
# Set home to the user's home directory
|
| 11 |
+
ENV HOME=/home/user \
|
| 12 |
+
PATH=/home/user/.local/bin:$PATH
|
| 13 |
+
# Set the working directory to the user's home directory
|
| 14 |
+
WORKDIR $HOME/app
|
| 15 |
+
|
| 16 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
| 17 |
+
COPY --chown=user . $HOME/app
|
| 18 |
+
RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
|
| 19 |
+
|
| 20 |
+
CMD ["workcell", "serve", "--config", "workcell.yaml", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
from typing import Dict, List, Optional
|
| 4 |
+
from pydantic import BaseModel, Field, SecretStr
|
| 5 |
+
from utils.summarizer import get_analyze_result
|
| 6 |
+
from workcell.integrations.types import MarkdownMixin
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class Input(BaseModel):
|
| 10 |
+
keywords: List[str] = Field(default=["name: weanalyze", "MIT", 'computer science', 'google'], max_items=20,
|
| 11 |
+
description="List of keyword to describe your education or work experience.")
|
| 12 |
+
openai_api_key: Optional[SecretStr] = Field(
|
| 13 |
+
..., description="OpenAI API key, provide if you have, or use our default key (may reach tier limit)."
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def generate_resume(input: Input) -> MarkdownMixin:
|
| 17 |
+
"""Returns a resume by several keywords, generated by OpenAI GPT3 API."""
|
| 18 |
+
openai.api_key = os.getenv('SECRET_OPENAI_WORKCELL_WEBPAGE_QA')
|
| 19 |
+
# return summarization
|
| 20 |
+
text = input.keywords
|
| 21 |
+
analyze = get_analyze_result(text)
|
| 22 |
+
output = MarkdownMixin(
|
| 23 |
+
data = analyze
|
| 24 |
+
)
|
| 25 |
+
return output
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
workcell
|
| 2 |
+
openai
|
utils/summarizer.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ast
|
| 2 |
+
import openai
|
| 3 |
+
|
| 4 |
+
# Prompt engineering
|
| 5 |
+
def get_prompt(text):
|
| 6 |
+
prompt_prefix = """Generate a markdown format resume for me by those keywords: {}"""
|
| 7 |
+
prompt = prompt_prefix.format(text)
|
| 8 |
+
return prompt
|
| 9 |
+
|
| 10 |
+
# Chat completion
|
| 11 |
+
def get_openai_chatcompletion(keywords):
|
| 12 |
+
"""Get OpenAI Chat Completion result.
|
| 13 |
+
"""
|
| 14 |
+
messages = []
|
| 15 |
+
processed_text = keywords
|
| 16 |
+
augmented_prompt = get_prompt(processed_text)
|
| 17 |
+
messages.append({"role":"user","content": augmented_prompt})
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
result = openai.ChatCompletion.create(
|
| 21 |
+
model="gpt-3.5-turbo",
|
| 22 |
+
messages=messages,
|
| 23 |
+
temperature=0.7
|
| 24 |
+
)
|
| 25 |
+
except:
|
| 26 |
+
raise
|
| 27 |
+
return result
|
| 28 |
+
|
| 29 |
+
# Process result
|
| 30 |
+
def get_analyze(result):
|
| 31 |
+
try:
|
| 32 |
+
analyze = result["choices"][0]["message"]["content"]
|
| 33 |
+
except:
|
| 34 |
+
raise
|
| 35 |
+
return analyze
|
| 36 |
+
|
| 37 |
+
def get_analyze_result(keywords):
|
| 38 |
+
result = get_openai_chatcompletion(keywords)
|
| 39 |
+
analyze = get_analyze(result)
|
| 40 |
+
return analyze
|
| 41 |
+
|
workcell.yaml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
workcell_name: generate_resume
|
| 2 |
+
workcell_provider: huggingface
|
| 3 |
+
workcell_id: weanalyze/generate_resume
|
| 4 |
+
workcell_version: latest
|
| 5 |
+
workcell_runtime: python3.8
|
| 6 |
+
workcell_entrypoint: app:generate_resume
|
| 7 |
+
workcell_code:
|
| 8 |
+
ImageUri: ''
|
| 9 |
+
workcell_tags: {}
|
| 10 |
+
workcell_envs: {}
|