Spaces:
Runtime error
Runtime error
File size: 2,120 Bytes
e4e0c90 |
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 |
import newspaper
from newspaper import*
import gradio as gr
import openai
openai.api_key = "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"
import validators
def predict(url_or_text, prompt, temperature, max_tokens):
text = url_or_text
if validators.url(url_or_text):
article = Article(url="%s" % (url_or_text), language='en')
article.download()
article.parse()
text = article.text
response = openai.Completion.create(
model="text-davinci-003",
prompt = text + "\n"+ prompt,
temperature=int(temperature),
max_tokens=int(max_tokens),
top_p=1,
frequency_penalty=0.0,
presence_penalty=1
)
return response.choices[0].text
intr = gr.Interface(predict, [gr.Textbox(value="https://www.datasciencecentral.com/will-chatgpt-make-fraud-easier/"),gr.Textbox(value="tl:dr"),gr.Number(value=0.7), gr.Number(value=100)],
"text", title = "Summmarizer", description = "For default summarizer give prompt as tl:dr, and temprature 0-1, higher the value, the more random will be the output. "
,examples=[['https://www.datasciencecentral.com/will-chatgpt-make-fraud-easier/', 'Get the gist of the article',0.7, 100],
["A neutron star is the collapsed core of a massive supergiant star, which had a total mass of between 10 and 25 solar masses, possibly more if the star was especially metal-rich.[1] Neutron stars are the smallest and densest stellar objects, excluding black holes and hypothetical white holes, quark stars, and strange stars.[2] Neutron stars have a radius on the order of 10 kilometres (6.2 mi) and a mass of about 1.4 solar masses.[3] They result from the supernova explosion of a massive star, combined with gravitational collapse, that compresses the core past white dwarf star density to that of atomic nuclei."
,"tl:dr",0.5, 50],
['https://www.datasciencecentral.com/enriching-customer-service-using-sentiment-analysis/','Summerize the crux of the above article for a linkedin post', 0.3,100]])
intr.launch(inline = False) |