-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathai_improver.py
59 lines (46 loc) · 2.59 KB
/
ai_improver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import openai
from utils import *
from constants import *
openai.api_key = OPENAIKEY
import streamlit as st
from io import StringIO
from PIL import Image
def general_corrector(prompt, temperature,model = OPENAIMODEL,max_tokens = 20):
openai.api_key = OPENAIKEY
res = openai.Completion.create(model=model,prompt=prompt,temperature=temperature,max_tokens=max_tokens)
return res['choices'][0]['text']
def single_experience_corrector(experience_text):
correct_text = general_corrector(prompt=EXPERIENCE_PROMPT_CONVERT+experience_text,temperature=0.4,max_tokens=200)
st.markdown("<span style='color:navy'>"+experience_text+"</span>",
unsafe_allow_html=True)
st.text('The AI suggests the following summary instead: \n')
#print(final_correction)
st.markdown("<span style='color:red'>"+correct_text+"</span>",
unsafe_allow_html=True)
return correct_text
def summary_corrector(summary_text):
print('The AI is rephrasing the text (if necessary): \n')
st.text('The AI is rephrasing the text (if necessary):\n')
first_correction = general_corrector(prompt=SUMMARY_PROMPT_CONVERT+summary_text,temperature=TEMPERATURE_SUMMARY_PROMPT_CONVERT,max_tokens=200)
print('The AI is improving the rephrased summary \n')
st.text('The AI is improving the rephrased summary \n')
final_correction = general_corrector(prompt=SUMMARY_PROMPT_IMPROVER+first_correction,temperature =TEMPERATURE_SUMMARY_PROMPT_IMPROVER,max_tokens=200)
print('The summary of your current CV is the following:\n')
st.text('The AI is improving the rephrased summary \n')
print(summary_text)
#st.text(summary_text)
st.text('The summary section of your CV is the following one: \n')
st.markdown("<span style='color:navy'>"+summary_text+"</span>",
unsafe_allow_html=True)
st.text('The AI suggests the following summary instead: \n')
print(final_correction)
st.markdown("<span style='color:red'>"+final_correction+"</span>",
unsafe_allow_html=True)
return final_correction
def summary_corrector_main(summary_text):
first_correction = general_corrector(prompt=SUMMARY_PROMPT_CONVERT+summary_text,temperature=TEMPERATURE_SUMMARY_PROMPT_CONVERT,max_tokens=200)
final_correction = general_corrector(prompt=SUMMARY_PROMPT_IMPROVER+first_correction,temperature =TEMPERATURE_SUMMARY_PROMPT_IMPROVER,max_tokens=200)
return final_correction
def single_experience_corrector_main(experience_text):
correct_text = general_corrector(prompt=EXPERIENCE_PROMPT_CONVERT+experience_text,temperature=0.4,max_tokens=200)
return correct_text