1st commit!
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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(prompt, model="gpt-3.5-turbo"):
|
| 12 |
+
messages = [{"role": "user", "content": prompt}]
|
| 13 |
+
response = openai.ChatCompletion.create(
|
| 14 |
+
model=model,
|
| 15 |
+
messages=messages,
|
| 16 |
+
temperature=0, # this is the degree of randomness of the model's output
|
| 17 |
+
)
|
| 18 |
+
return response.choices[0].message["content"]
|
| 19 |
+
|
| 20 |
+
def greet(company, solution, target_customer, problem, features):
|
| 21 |
+
|
| 22 |
+
pitch = f"""
|
| 23 |
+
My company, {company} is developing {solution} to help {target_customer} {problem} with {features}
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
prompt = f"""
|
| 27 |
+
Determine the product or solution, the problem being solved, features, target customer that are being discussed in the \
|
| 28 |
+
following text, which is delimited by triple backticks. Then, pretend that you are the target customer. \
|
| 29 |
+
State if you would use this product and elaborate on why. Also state if you would pay for it and elaborate on why.\
|
| 30 |
+
|
| 31 |
+
Format your response as a JSON object with \
|
| 32 |
+
'solution', 'problem', 'features', 'target_customer', 'fg_will_use', 'reason_to_use', 'fg_will_pay', 'reason_to_pay' as the keys.\
|
| 33 |
+
|
| 34 |
+
Text sample: '''{pitch}'''
|
| 35 |
+
"""
|
| 36 |
+
response = get_completion(prompt)
|
| 37 |
+
return json.dumps(response)
|
| 38 |
+
|
| 39 |
+
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 40 |
+
#iface.launch()
|
| 41 |
+
|
| 42 |
+
#iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Text to find entities", lines=2)], outputs=[gr.HighlightedText(label="Text with entities")], title="NER with dslim/bert-base-NER", description="Find entities using the `dslim/bert-base-NER` model under the hood!", allow_flagging="never", examples=["My name is Andrew and I live in California", "My name is Poli and work at HuggingFace"])
|
| 43 |
+
iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Company"), gr.Textbox(label="Solution"), gr.Textbox(label="Target Customer"), gr.Textbox(label="Problem"), gr.Textbox(label="Killer Feture")], outputs="json")
|
| 44 |
+
iface.launch()
|