File size: 3,011 Bytes
8013768
44e037d
8013768
c90ba26
 
8013768
c90ba26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import gradio as gr
import os

from dotenv import find_dotenv, load_dotenv
_ = load_dotenv(find_dotenv())


import openai
openai_client = openai.OpenAI()


def get_completion(prompt, model="gpt-4o-mini", temperature=0.5):
    messages = [{"role": "user", "content": prompt}]
    answer = openai_client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=temperature,
    )
    return answer.choices[0].message.content


def return_prompt(description, plan):
    return f"""

Your goal is to help me write a professional and winning proposal.

This is a job Description delimited with triple backticks i.e. ```:
```
{description}
```

First of all you need to write an Introdution based on given Description, 

Try to be brief and convincing.
If the person introduces himself by name, please use it in the greeting.
This is an example:
```
Hello! I see that you need help with ...
I could help with that, and I can start immediately.
```

Next, you need to convince the client that 
I am the perfect fit for this particular task.
So you are going to say that I have experience in the required technologies.
Name this technologies.
Be concrete, concise and creative.
Maximum 3 sentences.
This is an example:
```
I am a great fit for this because I am an experienced 
Machine Learning Engineer and I'm familiar with ... 
```

Next you have to translate into English the Plan of how I am going to solve this problem.
There is no need to invent anything here, just translate what I wrote and make the sound more natural.
Here is the plan, delimited by triple backticks, i.e. ```:
```
{plan}
```

Check the whole text for grammatical and stylistic errors.
The text should sound natural, friendly and professional!!!

Do not include part names or any comments.
Finish the text with:
```
Do you have any questions for me?

Kind regards
```
"""

def respond(description, plan):

    prompt = return_prompt(description, plan)

    try:
        response = get_completion(prompt)
    except openai.AuthenticationError as e:
        gr.Warning(f"OpenAI API request was not authorized: {e}")
        return "OpenAI API request was not authorized !"

    response = f"{response.strip()}\nNicolay"

    return response

with gr.Blocks(css = "footer {visibility: hidden}") as demo:

    with gr.Row():
        with gr.Column():
            translate_btn = gr.Button(value="Translate")
            description = gr.Textbox(
                placeholder="Description",
                show_label=False, 
                lines=2)
            plan = gr.Textbox(
                placeholder="Plan",
                show_label=False,
                lines=2)
        with gr.Column(scale=1):
            out = gr.Textbox(
                label="Output", 
                lines=5,
                # show_label=False,
                show_copy_button=True,
            )

    translate_btn.click(respond, [description,plan], out)

demo.queue().launch(auth=(os.getenv('USER') ,os.getenv('PASS')))