Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
|
4 |
+
|
5 |
+
model_name = "nouamanetazi/cover-letter-t5-base"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
8 |
+
|
9 |
+
|
10 |
+
def generate_cover_letter(
|
11 |
+
name, job, company, background, experiences, max_length=300, temperature=1.0, top_p=0.9, max_time=10
|
12 |
+
):
|
13 |
+
model_args = {
|
14 |
+
"max_length": max_length,
|
15 |
+
"temperature": temperature,
|
16 |
+
"top_p": top_p,
|
17 |
+
# "top_k": 120,
|
18 |
+
"early_stopping": True,
|
19 |
+
"max_time": max_time,
|
20 |
+
"do_sample": True, # do_sample=False to force deterministic output
|
21 |
+
"num_return_sequences": 1, # number of samples to return
|
22 |
+
"min_length": 100,
|
23 |
+
"num_beams": 4,
|
24 |
+
# "num_beam_groups": 1,
|
25 |
+
# "diversity_penalty": 0,
|
26 |
+
# "repetition_penalty": 5.0,
|
27 |
+
# "length_penalty": 0,
|
28 |
+
# "remove_invalid_values": True,
|
29 |
+
"no_repeat_ngram_size": 3,
|
30 |
+
}
|
31 |
+
# Load the tokenizer and the distilgpt2 model
|
32 |
+
# Set up the transformers pipeline
|
33 |
+
text_generator = pipeline(
|
34 |
+
"text2text-generation", model=model, tokenizer=tokenizer, device=0 if torch.cuda.is_available() else -1
|
35 |
+
)
|
36 |
+
# Generate the text
|
37 |
+
prompt = f"coverletter name: {name} job: {job} at {company} background: {background} experiences: {experiences}"
|
38 |
+
generated_text = text_generator(prompt, **model_args)[0]["generated_text"]
|
39 |
+
return generated_text
|
40 |
+
|
41 |
+
|
42 |
+
title = "A Cover Letter Generator"
|
43 |
+
description = ""
|
44 |
+
article = '<div style="text-align:center">This is a Space App for the project <a href="https://discuss.huggingface.co/t/build-a-cover-letter-generator/11721">build-a-cover-letter-generator</a> from the HuggingFace course 2 🤗 featuring a text generation model in english, based on the model t5-base.</div>'
|
45 |
+
examples = None
|
46 |
+
interface = gr.Interface(
|
47 |
+
fn=generate_cover_letter,
|
48 |
+
inputs=[
|
49 |
+
gr.inputs.Textbox(
|
50 |
+
label="Your name",
|
51 |
+
default="Sakil Ansari",
|
52 |
+
),
|
53 |
+
gr.inputs.Textbox(
|
54 |
+
label="The job you want to apply for",
|
55 |
+
default="Data Scientist",
|
56 |
+
),
|
57 |
+
gr.inputs.Textbox(
|
58 |
+
label="The company you want to apply for",
|
59 |
+
default="Google",
|
60 |
+
),
|
61 |
+
gr.inputs.Textbox(
|
62 |
+
lines=2,
|
63 |
+
label="Your education/background",
|
64 |
+
default="Master of Technology in Machine learning",
|
65 |
+
),
|
66 |
+
gr.inputs.Textbox(
|
67 |
+
lines=3,
|
68 |
+
label="Your skills/previous experiences",
|
69 |
+
default="I am the Author of Book and MTech in Machine Learning and achievement-driven professional with an experience of 3+ years in Data Science/Machine Learning/NLP/ Deep Learning/Data analytics. I am highly skilled in libraries like Sklearn, Numpy, Pandas, Matplotlib, Seaborn, Tensorflow, Faster-RCNN, Keras, Pytorch, FastAI, PowerBI/Tableau for Data Visualization, SQL/Oracle/NoSQL for databases and experience in NLP use cases related to named entity recognition, text summarization, text similarity, text generation.",
|
70 |
+
),
|
71 |
+
gr.inputs.Slider(20, 2048, default=400, label="Max Length"),
|
72 |
+
gr.inputs.Slider(0, 3, default=1.2, label="Temperature"),
|
73 |
+
gr.inputs.Slider(0, 1, default=0.9, label="Top P"),
|
74 |
+
gr.inputs.Slider(1, 200, default=20, label="Max time"),
|
75 |
+
],
|
76 |
+
outputs=[gr.outputs.Textbox(type="str", label="Cover Letter")],
|
77 |
+
title=title,
|
78 |
+
description=description,
|
79 |
+
examples=examples,
|
80 |
+
article=article,
|
81 |
+
layout="horizontal",
|
82 |
+
)
|
83 |
+
interface.launch(inline=False, debug=False)
|