|
import openai |
|
import os |
|
import gradio as gr |
|
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, |
|
) |
|
return response.choices[0].message["content"] |
|
|
|
def greet(input): |
|
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. |
|
|
|
Format your response as a list of items separated by commas. |
|
|
|
Text sample: '''{input}''' |
|
""" |
|
response = get_completion(prompt) |
|
return "Hello " + response + "!!" |
|
|
|
|
|
|
|
|
|
|
|
iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Elevator pitch", lines=3)], outputs="text") |
|
iface.launch() |
|
|