pr / app.py
nicola
Workbench workspace sync
c90ba26
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')))