Spaces:
Runtime error
Runtime error
import requests | |
import os | |
gpt3_key = os.environ['GPT3_API_KEY'] | |
def gpt3_endpoint(api_key, prompt): | |
api_endpoint = "https://api.openai.com/v1/engines/text-davinci-003/completions" | |
headers = { | |
"Content-Type": "application/json", | |
"Authorization": f"Bearer {api_key}" | |
} | |
data = { | |
"prompt": prompt, | |
"max_tokens": 200, | |
"temperature": 0.8 | |
} | |
response = requests.post(api_endpoint, headers=headers, json=data) | |
generated_text = response.json()["choices"][0]["text"] | |
return generated_text | |
# prompt = """ | |
# Write a one minute pitch with innovative tone for a startup with the following info: | |
# what does the startup do? Creating software powered with GPT3 | |
# industry: AI | |
# audience of the pitch: clients | |
# vision of the startup: Empower businesses with the power of next-gen technology | |
# """ | |
# gpt3_endpoint(prompt) | |
import gradio as gr | |
#the first module becomes text1, the second module file1 | |
def greet(length, name, do, tone, audience, vision): | |
prompt = f""" | |
Write a {length} with {tone} tone for a startup with the following info: | |
The name of the startup: {name} | |
what does the startup do? {do} | |
audience of the pitch: {audience} | |
vision of the startup: {vision} | |
""" | |
return gpt3_endpoint(gpt3_key, prompt).replace('\n', ' ').strip() | |
with gr.Blocks() as demo: | |
gr.Markdown( | |
""" | |
# GPT3 startup pitch writer | |
""" | |
) | |
input1 = gr.Radio(["3-minute pitch", "1-minute pitch", "sentence"], label="length", value='sentence') | |
input2 = gr.Text(headers=["q1"], label="What is the name of your Startup?", value='Goliath AI Consulting') | |
input3 = gr.Text(headers=["q2"], label="What does your startup do?", value='We build AI Recommendation Systems') | |
input4 = gr.Radio(["professional", "funny", "innovative", "challenging"], label="Tone", value='innovative') | |
input5 = gr.Radio(["clients", "VCs", "social media"], label="Pitch Audience", value='VCs') | |
input6 = gr.Text(headers=["q5"], label="What is the vision of your company?", value='empowering companies with the latest AI') | |
btn = gr.Button(value="Write a Pitch!") | |
state = gr.Text(label="Output") | |
btn.click(greet, [input1, input2, input3, input4, input5, input6], [state]) | |
demo.launch(share=False) | |
# iface = gr.Interface( | |
# fn=greet, | |
# title='GPT3 startup pitch writer', | |
# inputs=[ | |
# gr.Radio(["1-minute pitch", "sentence"], label="length", value='sentence'), | |
# gr.Text(headers=["q1"], label="What is the name of your Startup?", value='Goliath AI Consulting'), | |
# gr.Text(headers=["q2"], label="What does your startup do?", value='We build AI Recommendation Systems'), | |
# gr.Radio(["professional", "funny", "innovative", "challenging"], label="Tone", value='innovative'), | |
# | |
# ], | |
# outputs='text' | |
# ) | |
# iface.launch(share=False) |