add
This commit is contained in:
parent
1a89f1c782
commit
493d3b4b0e
|
@ -0,0 +1,36 @@
|
|||
import gradio as gr
|
||||
from transformers import pipeline, set_seed
|
||||
import random, re
|
||||
|
||||
|
||||
gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
|
||||
|
||||
def generate_prompt(text):
|
||||
seed = random.randint(100, 1000000)
|
||||
set_seed(seed)
|
||||
|
||||
response = gpt2_pipe(text, max_length=(len(text) + random.randint(60, 90)), num_return_sequences=4)
|
||||
response_list = []
|
||||
for x in response:
|
||||
resp = x['generated_text'].strip()
|
||||
if resp != text and len(resp) > (len(text) + 4) and resp.endswith((":", "-", "—")) is False:
|
||||
response_list.append(resp+'\n')
|
||||
|
||||
response_end = "\n".join(response_list)
|
||||
response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
|
||||
response_end = response_end.replace("<", "").replace(">", "")
|
||||
|
||||
if response_end != "":
|
||||
return response_end
|
||||
|
||||
demo = gr.Interface(fn=generate_prompt,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[["A new hours out of fiend"], ["Third compendium of prague"]],
|
||||
title = "生成prompt"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
|
@ -0,0 +1,23 @@
|
|||
import gradio as gr
|
||||
from transformers import pipeline
|
||||
|
||||
|
||||
summarizer = pipeline("summarization", model="knkarthick/bart-large-xsum-samsum")
|
||||
|
||||
def sentiment_analysis(text):
|
||||
result = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
||||
|
||||
return result[0].get('summary_text')
|
||||
|
||||
|
||||
demo = gr.Interface(fn=sentiment_analysis,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[['The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.']],
|
||||
title = "摘要"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
|
@ -0,0 +1,23 @@
|
|||
import gradio as gr
|
||||
from transformers import pipeline
|
||||
|
||||
|
||||
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
||||
|
||||
def sentiment_analysis(text):
|
||||
result = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
||||
|
||||
return result[0].get('summary_text')
|
||||
|
||||
|
||||
demo = gr.Interface(fn=sentiment_analysis,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[['The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.']],
|
||||
title = "摘要"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
|
@ -0,0 +1,36 @@
|
|||
import gradio as gr
|
||||
from transformers import pipeline
|
||||
|
||||
|
||||
summarizer = pipeline("summarization", model="knkarthick/bart-large-xsum-samsum")
|
||||
|
||||
def sentiment_analysis(text):
|
||||
result = summarizer(text)
|
||||
|
||||
return result[0].get('summary_text')
|
||||
|
||||
|
||||
demo = gr.Interface(fn=sentiment_analysis,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[['''Hannah: Hey, do you have Betty's number?
|
||||
Amanda: Lemme check
|
||||
Amanda: Sorry, can't find it.
|
||||
Amanda: Ask Larry
|
||||
Amanda: He called her last time we were at the park together
|
||||
Hannah: I don't know him well
|
||||
Amanda: Don't be shy, he's very nice
|
||||
Hannah: If you say so..
|
||||
Hannah: I'd rather you texted him
|
||||
Amanda: Just text him 🙂
|
||||
Hannah: Urgh.. Alright
|
||||
Hannah: Bye
|
||||
Amanda: Bye bye
|
||||
''']],
|
||||
title = "摘要"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
|
@ -0,0 +1,26 @@
|
|||
import gradio as gr
|
||||
from transformers import pipeline
|
||||
import torch
|
||||
|
||||
|
||||
model_name = 'sshleifer/distilbart-cnn-12-6'
|
||||
summarizer = pipeline("summarization", model=model_name, tokenizer=model_name, device=0 if torch.cuda.is_available() else -1)
|
||||
|
||||
def sentiment_analysis(text):
|
||||
result = summarizer(text, max_length=130, min_length=30, clean_up_tokenization_spaces=True, no_repeat_ngram_size=4)
|
||||
summarized_text = ' '.join([summ['summary_text'] for summ in result])
|
||||
|
||||
return summarized_text
|
||||
|
||||
|
||||
demo = gr.Interface(fn=sentiment_analysis,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[['The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.']],
|
||||
title = "摘要"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
|
@ -0,0 +1,44 @@
|
|||
import gradio as gr
|
||||
from transformers import pipeline
|
||||
import torch
|
||||
|
||||
|
||||
model_name = 'google/pegasus-cnn_dailymail'
|
||||
summarization_model = pipeline('summarization', model=model_name, tokenizer=model_name, device=0 if torch.cuda.is_available() else -1)
|
||||
|
||||
def generate_abstractive_summary(text, type, min_len=120, max_len=512, **kwargs):
|
||||
text = text.strip().replace("\n", " ")
|
||||
if type == "top_p":
|
||||
text = summarization_model(text, min_length=min_len,
|
||||
max_length=max_len,
|
||||
top_k=50, top_p=0.95, clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
elif type == "greedy":
|
||||
text = summarization_model(text, min_length=min_len,
|
||||
max_length=max_len, clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
elif type == "top_k":
|
||||
text = summarization_model(text, min_length=min_len, max_length=max_len, top_k=50,
|
||||
clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
elif type == "beam":
|
||||
text = summarization_model(text, min_length=min_len,
|
||||
max_length=max_len,
|
||||
clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
summary = text[0]['summary_text'].replace("<n>", " ")
|
||||
|
||||
return summary
|
||||
|
||||
def sentiment_analysis(text):
|
||||
summary_content = generate_abstractive_summary(text, type="beam", do_sample=True, num_beams=15,no_repeat_ngram_size=4)
|
||||
|
||||
return summary_content
|
||||
|
||||
demo = gr.Interface(fn=sentiment_analysis,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[['The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.']],
|
||||
title = "摘要"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
|
@ -0,0 +1,44 @@
|
|||
import gradio as gr
|
||||
from transformers import pipeline
|
||||
import torch
|
||||
|
||||
|
||||
model_name = 'google/pegasus-xsum'
|
||||
summarization_model = pipeline('summarization', model=model_name, tokenizer=model_name, device=0 if torch.cuda.is_available() else -1)
|
||||
|
||||
def generate_abstractive_summary(text, type, min_len=120, max_len=512, **kwargs):
|
||||
text = text.strip().replace("\n", " ")
|
||||
if type == "top_p":
|
||||
text = summarization_model(text, min_length=min_len,
|
||||
max_length=max_len,
|
||||
top_k=50, top_p=0.95, clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
elif type == "greedy":
|
||||
text = summarization_model(text, min_length=min_len,
|
||||
max_length=max_len, clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
elif type == "top_k":
|
||||
text = summarization_model(text, min_length=min_len, max_length=max_len, top_k=50,
|
||||
clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
elif type == "beam":
|
||||
text = summarization_model(text, min_length=min_len,
|
||||
max_length=max_len,
|
||||
clean_up_tokenization_spaces=True, truncation=True, **kwargs)
|
||||
summary = text[0]['summary_text'].replace("<n>", " ")
|
||||
|
||||
return summary
|
||||
|
||||
def sentiment_analysis(text):
|
||||
summary_content = generate_abstractive_summary(text, type="beam", do_sample=True, num_beams=15,no_repeat_ngram_size=4)
|
||||
|
||||
return summary_content
|
||||
|
||||
demo = gr.Interface(fn=sentiment_analysis,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[['The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct.']],
|
||||
title = "摘要"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
|
@ -0,0 +1,23 @@
|
|||
import gradio as gr
|
||||
from simplet5 import SimpleT5
|
||||
|
||||
|
||||
model = SimpleT5()
|
||||
model.load_model("t5","snrspeaks/t5-one-line-summary")
|
||||
|
||||
def sentiment_analysis(text):
|
||||
result = model.predict(text)
|
||||
|
||||
return result[0]
|
||||
|
||||
demo = gr.Interface(fn=sentiment_analysis,
|
||||
inputs='text',
|
||||
outputs='text',
|
||||
examples=[["We describe a system called Overton, whose main design goal is to support engineers in building, monitoring, and improving production machinelearning systems. Key challenges engineers face are monitoring fine-grained quality, diagnosing errors in sophisticated applications, and handling contradictory or incomplete supervision data. Overton automates the life cycle of model construction, deployment, and monitoring by providing a set of novel high-level, declarative abstractions. Overton's vision is to shift developers to these higher-level tasks instead of lower-level machine learning tasks. In fact, using Overton, engineers can build deep-learning-based applications without writing any code in frameworks like TensorFlow. For over a year, Overton has been used in production to support multiple applications in both near-real-time applications and back-of-house processing. In that time, Overton-based applications have answered billions of queries in multiple languages and processed trillions of records reducing errors 1.7-2.9 times versus production systems."]],
|
||||
title = "摘要"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo.queue(concurrency_count=3)
|
||||
demo.launch(server_name = "0.0.0.0", server_port = 7028)
|
Loading…
Reference in New Issue