File size: 2,074 Bytes
5cc8c4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b87769f
5cc8c4c
 
 
 
d9b0306
5cc8c4c
 
 
4e107e4
5cc8c4c
b87769f
5cc8c4c
 
 
8000afb
5cc8c4c
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
import openai
import os
import gradio as gr
import json
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())


openai.api_key  = os.getenv('OPENAI_API_KEY')

def get_completion_from_messages(messages,
                                 model="gpt-3.5-turbo",
                                 temperature=0,
                                 max_tokens=500):
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=temperature, # this is the degree of randomness of the model's output
        max_tokens=max_tokens, # the maximum number of tokens the model can ouptut
    )
    return response.choices[0].message["content"]

def greet(company, solution, target_customer, problem, features, target_audience_persona="the target customer"):
    pitch = f"""My company, {company} is developing {solution} to help {target_customer} {problem} with {features}"""
    sys_setup = f"""
Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
following user prompt. State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
Finally, state if you would invest in it and elaborate on why.\
Give a score for the product.

Format your response as a JSON object with \
'solution', 'problem', 'features', 'target_customer', 'fg_will_use', 'reason_to_use', 'fg_will_pay', 'reason_to_pay', 'fg_will_invest', 'reason_to_invest', 'score' as the keys.
    """
    messages = [{'role':'system', 'content':"You are " + target_audience_persona + "."}, {'role':'system', 'content': sys_setup}, {'role':'user','content':pitch}]
    response = get_completion_from_messages(messages, temperature=0)
    return json.dumps(response)

iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Company"), gr.Textbox(label="Solution"), gr.Textbox(label="Customer"), gr.Textbox(label="Problem"), gr.Textbox(label="Feature"), gr.Textbox(label="Target Audience persona", lines=3)], outputs="json")
iface.launch()