File size: 1,660 Bytes
c561df3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import openai
import gradio as gr
import datetime

initial_prompt = "List the following in a HTML table with about 10 rows in an appropriate order, giving the table an appropriate caption. The table contains about 5 columns with appropriate attributes. Each non-numeric cell in the table, regardless of column, contains a link whenever possible to an appropriate Wikipedia page that opens in a new tab. No other links besides Wikipedia pages are permitted: "
title_prompt = "Write a title without quotation marks for a table that contains the following information: "
prompt = ""

def openai_create(prompt):
    print("\n==== date/time: " + str(datetime.datetime.now()) + " ====")
    print("prompt: " + prompt)

    response = openai.Completion.create(
    model="text-davinci-003",
    prompt=prompt,
    temperature=0.1,
    max_tokens=2000,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
    )

    return response.choices[0].text


def desc2sheet(desc):
    html = openai_create(initial_prompt + desc + '\n')
    return html

block = gr.Blocks(css=".gradio-container {background-color: lightgray}")

with block:
    title = gr.Markdown("""<h3><center>GPT-3.5 Table-inator</center></h3>""")
    table = gr.Markdown("")
    with gr.Row():
        request = gr.Textbox(label=initial_prompt,
                             placeholder="Ex: 12 computer languages and their inventors by year of birth")

        submit = gr.Button(value="Create", variant="secondary").style(full_width=False)

    submit.click(desc2sheet, inputs=[request], outputs=[table])
    request.submit(desc2sheet, inputs=[request], outputs=[table])

block.launch()