Spaces:
Sleeping
Sleeping
ravithejads
commited on
Commit
·
e938e19
1
Parent(s):
e7703c4
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
def factgenerator(text, num_facts, openaikey):
|
5 |
+
|
6 |
+
if not text:
|
7 |
+
return "Enter some text to check facts"
|
8 |
+
|
9 |
+
facts = "one"
|
10 |
+
|
11 |
+
if num_facts == 1:
|
12 |
+
facts = "one"
|
13 |
+
elif num_facts == 2:
|
14 |
+
facts = "two"
|
15 |
+
elif num_facts == 3:
|
16 |
+
facts = "three"
|
17 |
+
elif num_facts == 4:
|
18 |
+
facts = "four"
|
19 |
+
elif num_facts == 5:
|
20 |
+
facts = "five"
|
21 |
+
|
22 |
+
openai.api_key = openaikey
|
23 |
+
|
24 |
+
response = openai.Completion.create(
|
25 |
+
model="text-davinci-003",
|
26 |
+
prompt="How long before the FBI raids @elonmusk's home?\nFBI\n• The FBI was founded in 1908 and is a federal investigative agency.\n\nElon Musk\n• Elon Musk is a South African-born American business magnate, investor, and inventor.\n\nSimilar to the above format, generate " + facts + " facts for each entity present in the text.\n" + text + "." + "\n\n",
|
27 |
+
temperature=0.7,
|
28 |
+
max_tokens=3900,
|
29 |
+
top_p=1,
|
30 |
+
frequency_penalty=0,
|
31 |
+
presence_penalty=0
|
32 |
+
)
|
33 |
+
return response['choices'][0]['text']
|
34 |
+
|
35 |
+
with gr.Blocks() as demo:
|
36 |
+
gr.Markdown(
|
37 |
+
"""
|
38 |
+
# FactGen!
|
39 |
+
To get a better understanding of the text, this app gives facts about the entities present in the text. The app uses OpenAI GPT3 in the backend, get your Openai key here - https://beta.openai.com/account/api-keys \n
|
40 |
+
Start typing below or select one from examples at the bottom, use the Dropdown to select the Number of facts per entity, and enter your openai key to see the output.
|
41 |
+
""")
|
42 |
+
with gr.Row():
|
43 |
+
with gr.Column():
|
44 |
+
text = gr.Textbox(lines = 5, placeholder = "PM Modi to visit Tripura tomorrow; govt expects 72,000 to attend his public meeting", label = "Enter text")
|
45 |
+
num_facts = gr.Dropdown([1, 2, 3, 4, 5],label="Click here to select Number of facts for each entity", value = 1)
|
46 |
+
openaikey = gr.Textbox(lines = 1, label = "Enter Openai Key")
|
47 |
+
text_button = gr.Button("Submit")
|
48 |
+
with gr.Column():
|
49 |
+
text_output = gr.Textbox(label = "Output")
|
50 |
+
|
51 |
+
text_button.click(factgenerator, inputs=[text, num_facts, openaikey], outputs=text_output)
|
52 |
+
# We can choose text from one of the following examples
|
53 |
+
gr.Examples([["Elizabeth Warren Prods Tesla About Elon Musk and Twitter"],
|
54 |
+
["Chelsea news and transfers LIVE: Christopher Nkunku confirmed, Bellingham move, Moukoko contract"],
|
55 |
+
["PM Modi to visit Tripura tomorrow; govt expects 72,000 to attend his public meeting"],
|
56 |
+
["Biden to deliver Patriot missiles to Ukraine as Zelenskyy visits Washington."],
|
57 |
+
["Meet the AI Pioneers Who Won The 2022 Princess of Asturias Award"]],
|
58 |
+
inputs = [text])
|
59 |
+
|
60 |
+
demo.launch()
|