magic2 / app.py
debisoft's picture
revert to gpt 3.5
c0f5ad8
raw
history blame
1.6 kB
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(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0, # this is the degree of randomness of the model's output
)
return response.choices[0].message["content"]
def greet(company, solution, target_customer, problem, features):
pitch = f"""My company, {company} is developing {solution} to help {target_customer} {problem} with {features}"""
prompt = f"""
Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
following text, which is delimited by triple backticks. Then, pretend that you are the target customer. \
State if you would use this product and elaborate on why. Also state if you would pay for 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', 'score' as the keys.
Text sample: '''{pitch}'''
"""
response = get_completion(prompt)
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")], outputs="json")
iface.launch()