Spaces:
Build error
Build error
Initial commit
Browse files- app.py +45 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
import datetime
|
5 |
+
|
6 |
+
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: "
|
7 |
+
title_prompt = "Write a title without quotation marks for a table that contains the following information: "
|
8 |
+
prompt = ""
|
9 |
+
|
10 |
+
def openai_create(prompt):
|
11 |
+
print("\n==== date/time: " + str(datetime.datetime.now()) + " ====")
|
12 |
+
print("prompt: " + prompt)
|
13 |
+
|
14 |
+
response = openai.Completion.create(
|
15 |
+
model="text-davinci-003",
|
16 |
+
prompt=prompt,
|
17 |
+
temperature=0.1,
|
18 |
+
max_tokens=2000,
|
19 |
+
top_p=1,
|
20 |
+
frequency_penalty=0,
|
21 |
+
presence_penalty=0
|
22 |
+
)
|
23 |
+
|
24 |
+
return response.choices[0].text
|
25 |
+
|
26 |
+
|
27 |
+
def desc2sheet(desc):
|
28 |
+
html = openai_create(initial_prompt + desc + '\n')
|
29 |
+
return html
|
30 |
+
|
31 |
+
block = gr.Blocks(css=".gradio-container {background-color: lightgray}")
|
32 |
+
|
33 |
+
with block:
|
34 |
+
title = gr.Markdown("""<h3><center>GPT-3.5 Table-inator</center></h3>""")
|
35 |
+
table = gr.Markdown("")
|
36 |
+
with gr.Row():
|
37 |
+
request = gr.Textbox(label=initial_prompt,
|
38 |
+
placeholder="Ex: 12 computer languages and their inventors by year of birth")
|
39 |
+
|
40 |
+
submit = gr.Button(value="Create", variant="secondary").style(full_width=False)
|
41 |
+
|
42 |
+
submit.click(desc2sheet, inputs=[request], outputs=[table])
|
43 |
+
request.submit(desc2sheet, inputs=[request], outputs=[table])
|
44 |
+
|
45 |
+
block.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
gradio
|