1st commit!
Browse files- app.py +38 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import json
|
| 5 |
+
from dotenv import load_dotenv, find_dotenv
|
| 6 |
+
_ = load_dotenv(find_dotenv())
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
openai.api_key = os.getenv('OPENAI_API_KEY')
|
| 10 |
+
|
| 11 |
+
def get_completion_from_messages(messages,
|
| 12 |
+
model="gpt-3.5-turbo",
|
| 13 |
+
temperature=0,
|
| 14 |
+
max_tokens=500):
|
| 15 |
+
response = openai.ChatCompletion.create(
|
| 16 |
+
model=model,
|
| 17 |
+
messages=messages,
|
| 18 |
+
temperature=temperature, # this is the degree of randomness of the model's output
|
| 19 |
+
max_tokens=max_tokens, # the maximum number of tokens the model can ouptut
|
| 20 |
+
)
|
| 21 |
+
return response.choices[0].message["content"]
|
| 22 |
+
|
| 23 |
+
def greet(company, solution, target_customer, problem, features, customer_persona="the target customer"):
|
| 24 |
+
pitch = f"""My company, {company} is developing {solution} to help {target_customer} {problem} with {features}"""
|
| 25 |
+
sys_setup = f"""
|
| 26 |
+
Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
|
| 27 |
+
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.\
|
| 28 |
+
Give a score for the product.
|
| 29 |
+
|
| 30 |
+
Format your response as a JSON object with \
|
| 31 |
+
'solution', 'problem', 'features', 'target_customer', 'fg_will_use', 'reason_to_use', 'fg_will_pay', 'reason_to_pay', 'score' as the keys.
|
| 32 |
+
"""
|
| 33 |
+
messages = [{'role':'system', 'content':"You are " + customer_persona + "."}, {'role':'system', 'content': sys_setup}, {'role':'user','content':pitch}]
|
| 34 |
+
response = get_completion_from_messages(messages, temperature=0)
|
| 35 |
+
return json.dumps(response)
|
| 36 |
+
|
| 37 |
+
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="Customer persona", lines=3)], outputs="json")
|
| 38 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
python-dotenv
|