Spaces:
Runtime error
Runtime error
Jingxiang Mo commited on
Commit ·
9522bb7
1
Parent(s): a381bc0
debug
Browse files123456782 unmodified lines1112131415169 unmodified lines262728293031323334353637385 unmodified lines44454647484950515253545556575859import osimport gradio as grimport wikipediaapi as wkfrom transformers import (TokenClassificationPipeline,AutoModelForTokenClassification,2 unmodified linesfrom transformers.pipelines import AggregationStrategyimport numpy as npclass KeyphraseExtractionPipeline(TokenClassificationPipeline):def __init__(self, model, *args, **kwargs):super().__init__(9 unmodified linesaggregation_strategy=AggregationStrategy.SIMPLE,)return np.unique([result.get("word").strip() for result in results])# Load pipelinemodel_name = "ml6team/keyphrase-extraction-kbir-inspec"extractor = KeyphraseExtractionPipeline(model=model_name)def keyphrases_out(input): #Not used but might be usefulinput = input.replace("\n", " ")keyphrases = extractor(input)out = "The Key Phrases in your text are:\n\n"5 unmodified linesinput = input.replace("\n", " ")keyphrases = extractor(input)wiki = wk.Wikipedia('en')for k in keyphrases:page = wiki.page(k)if page.exists():breakreturn page.summarydemo = gr.Interface(fn=wikipedia_search, inputs = "text", outputs = "text")demo.launch()1234562 unmodified lines91011121314159 unmodified lines25262728293031323334353637383940414243444546474849505152535455565758595 unmodified lines65666768697071727374757677787980818283848586import osimport gradio as grimport wikipediaapi as wkfrom transformers import (TokenClassificationPipeline,AutoModelForTokenClassification,2 unmodified linesfrom transformers.pipelines import AggregationStrategyimport numpy as np# =====[ DEFINE PIPELINE ]===== #class KeyphraseExtractionPipeline(TokenClassificationPipeline):def __init__(self, model, *args, **kwargs):super().__init__(9 unmodified linesaggregation_strategy=AggregationStrategy.SIMPLE,)return np.unique([result.get("word").strip() for result in results])# =====[ LOAD PIPELINE ]===== #model_name = "ml6team/keyphrase-extraction-kbir-inspec"extractor = KeyphraseExtractionPipeline(model=model_name)text = """Keyphrase extraction is a technique in text analysis where you extract theimportant keyphrases from a document. Thanks to these keyphrases humans canunderstand the content of a text very quickly and easily without reading itcompletely. Keyphrase extraction was first done primarily by human annotators,who read the text in detail and then wrote down the most important keyphrases.The disadvantage is that if you work with a lot of documents, this processcan take a lot of time.Here is where Artificial Intelligence comes in. Currently, classical machinelearning methods, that use statistical and linguistic features, are widely usedfor the extraction process. Now with deep learning, it is possible to capturethe semantic meaning of a text even better than these classical methods.Classical methods look at the frequency, occurrence and order of wordsin the text, whereas these neural approaches can capture long-termsemantic dependencies and context of words in a text.""".replace("\n", " ")keyphrases = extractor(text)print(keyphrases)def keyphrases_out(input):input = input.replace("\n", " ")keyphrases = extractor(input)out = "The Key Phrases in your text are:\n\n"5 unmodified linesinput = input.replace("\n", " ")keyphrases = extractor(input)wiki = wk.Wikipedia('en')page = wiki.page("")return page.summary# for k in keyphrases:# page = wiki.page(k)# if page.exists():# break# return page.summary# =====[ DEFINE INTERFACE ]===== #'# demo = gr.Interface(fn=wikipedia_search, inputs = "text", outputs = "text")# demo.launch(share=True)
app.py+38-11