Spaces:
Runtime error
Runtime error
File size: 7,200 Bytes
dcef704 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"\n",
"def gpt3_endpoint(prompt):\n",
" api_endpoint = \"https://api.openai.com/v1/engines/text-davinci-003/completions\"\n",
" api_key = \"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\"\n",
"\n",
" headers = {\n",
" \"Content-Type\": \"application/json\",\n",
" \"Authorization\": f\"Bearer {api_key}\"\n",
" }\n",
"\n",
" data = {\n",
" \"prompt\": prompt,\n",
" \"max_tokens\": 200,\n",
" \"temperature\": 0.8\n",
" }\n",
"\n",
" response = requests.post(api_endpoint, headers=headers, json=data)\n",
" generated_text = response.json()[\"choices\"][0][\"text\"]\n",
" return generated_text"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'\\nAre you ready to take your business to the next level? Our startup is here to help you do just that with our revolutionary software powered with GPT3. We are revolutionizing the AI industry by empowering businesses with the power of next-gen technology. Our software uses GPT3 to generate natural language processing and generate insights that can be used to improve your business in ways you never thought possible. We are here to help you unlock the power of AI and take your business to the next level.'"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" Write a one minute pitch with innovative tone for a startup with the following info:\n",
" what does the startup do? Creating software powered with GPT3\n",
" industry: AI\n",
" audience of the pitch: clients\n",
" vision of the startup: Empower businesses with the power of next-gen technology\n",
" \n"
]
}
],
"source": [
"prompt = \"\"\"\n",
"Write a one minute pitch with innovative tone for a startup with the following info:\n",
"what does the startup do? Creating software powered with GPT3\n",
"industry: AI\n",
"audience of the pitch: clients\n",
"vision of the startup: Empower businesses with the power of next-gen technology\n",
"\"\"\"\n",
"gpt3_endpoint(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Textbox, please remove them: {'headers': ['q1']}\n",
" warnings.warn(\n",
"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Textbox, please remove them: {'headers': ['q2']}\n",
" warnings.warn(\n",
"c:\\Users\\ardit\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\gradio\\deprecation.py:43: UserWarning: You have unused kwarg parameters in Textbox, please remove them: {'headers': ['q5']}\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running on local URL: http://127.0.0.1:7888\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7888/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import gradio as gr\n",
"\n",
"#the first module becomes text1, the second module file1\n",
"def greet(length, name, do, tone, audience, vision): \n",
" prompt = f\"\"\"\n",
" Write a {length} with {tone} tone for a startup with the following info:\n",
" The name of the startup: {name}\n",
" what does the startup do? {do}\n",
" audience of the pitch: {audience}\n",
" vision of the startup: {vision}\n",
" \"\"\"\n",
" return gpt3_endpoint(prompt).replace('\\n', ' ').strip()\n",
"\n",
"# iface = gr.Interface(\n",
"# fn=greet,\n",
"# title='GPT3 startup pitch writer',\n",
"# inputs=[\n",
"# gr.Radio([\"3-minute pitch\", \"1-minute pitch\", \"sentence\"], label=\"length\", value='sentence'),\n",
"# gr.Text(headers=[\"q1\"], label=\"What is the name of your Startup?\", value=\"Goliath AI Consulting\"),\n",
"# gr.Text(headers=[\"q2\"], label=\"What does your startup do?\", value='Creating software powered with GPT3'),\n",
"# gr.Radio([\"professional\", \"funny\", \"innovative\", \"challenging\"], label=\"Tone\", value='innovative'),\n",
"# gr.Radio([\"clients\", \"VCs\", \"social media\"], label=\"Pitch Audience\", value='clients'),\n",
"# gr.Text(headers=[\"q5\"], label=\"What is the vision of your company?\", value='Empower businesses with the power of next-gen technology')\n",
"# ],\n",
"# outputs='text'\n",
"# )\n",
"# iface.launch(share=False)\n",
"#BUG, if we try to run ONLY it on local without using share=True returns blank screen, but by sharing it it also work on localhost\n",
"\n",
"\n",
"iface = gr.Interface(\n",
" fn=greet,\n",
" title='GPT3 startup pitch writer',\n",
" inputs=[\n",
" gr.Radio([\"3-minute pitch\", \"1-minute pitch\", \"sentence\"], label=\"length\"),\n",
" gr.Text(headers=[\"q1\"], label=\"What is the name of your Startup?\"),\n",
" gr.Text(headers=[\"q2\"], label=\"What does your startup do?\"),\n",
" gr.Radio([\"professional\", \"funny\", \"innovative\", \"challenging\"], label=\"Tone\"),\n",
" gr.Radio([\"clients\", \"VCs\", \"social media\"], label=\"Pitch Audience\"),\n",
" gr.Text(headers=[\"q5\"], label=\"What is the vision of your company?\")\n",
" ],\n",
" outputs='text'\n",
")\n",
"iface.launch(share=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|