Ali-C137 commited on
Commit
3c162d3
1 Parent(s): 0683928

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Motivation-Letter-Generator
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1ZjAxQWoA9ECi-WgAMVm0HyonnrFFMlHG
8
+ """
9
+
10
+ ! pip install transformers
11
+ ! pip install gradio
12
+
13
+ from transformers import AutoModelForCausalLM, AutoTokenizer, set_seed, pipeline
14
+ import gradio as gr
15
+
16
+ import torch
17
+ torch.set_default_tensor_type(torch.cuda.FloatTensor)
18
+
19
+ ### need more GPU power to call better models !!!!!!
20
+
21
+ # from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
22
+ # tokenizer = AutoTokenizer.from_pretrained("bigscience/T0pp")
23
+ # model = AutoModelForSeq2SeqLM.from_pretrained("bigscience/T0pp") # 11B param
24
+
25
+ model = AutoModelForCausalLM.from_pretrained('EleutherAI/gpt-neo-1.3B', use_cache=True)
26
+ tokenizer = AutoTokenizer.from_pretrained('EleutherAI/gpt-neo-1.3B')
27
+
28
+ set_seed(424242)
29
+
30
+ def generate(Name, Employer, Position, Organization, Hard_skills, Soft_skills, max_length=500, top_k=1, temperature=0.9, repetition_penalty = 2.0):
31
+ prompt = f'im {Name} and i want to write a motivation letter to {Employer} about the position {Position} at {Organization} mentioning the hard skills {Hard_skills} and soft skills {Soft_skills} you have acquired'
32
+ input_ids = tokenizer(prompt, return_tensors="pt").to(0)
33
+ sample = model.generate(**input_ids, max_length=max_length, top_k=top_k, temperature=temperature, repetition_penalty = repetition_penalty)
34
+ return tokenizer.decode(sample[0], truncate_before_pattern=[r"\n\n^#", "^'''", "\n\n\n"])
35
+
36
+ title = "Motivation Letter Generator w/ GPT-Neo-1.3B"
37
+ article = "Colab is not really offering GPUs to load the big guns like 176B BLOOM so this is a toy demo, But if you have enough resources feel free to contact me and i'll send you the notebook, my contact: ali.elfilali00@gmail.com"
38
+
39
+ gr.Interface(
40
+ fn=generate,
41
+ inputs=["text", "text", "text", "text", "text", "text"],
42
+ outputs="text",
43
+ title=title,
44
+ article=article).launch()
45
+
46
+
47
+