Spaces:
Sleeping
Sleeping
from typing import Dict, Union, List | |
from .base_pipeline import transformers_pipeline | |
import gradio as gr | |
text1 = """ | |
The mechanism of action was characterized using native mass spectrometry, the thermal shift-binding assay, and enzymatic kinetic studies (Figure ). In the native mass spectrometry binding assay, compound 23R showed dose-dependent binding to SARS-CoV-2 Mpro, similar to the positive control GC376, with a binding stoichiometry of one drug per monomer (Figure A). | |
Similarly, compound 23R showed dose-dependent stabilization of the SARS-CoV-2 Mpro in the thermal shift binding assay with an apparent Kd value of 9.43 μM, a 9.3-fold decrease compared to ML188 (1) (Figure B). In the enzymatic kinetic studies, 23R was shown to be a noncovalent inhibitor with a Ki value of 0.07 μM (Figure C, D top and middle panels). In comparison, the Ki for the parent compound ML188 (1) is 2.29 μM. | |
The Lineweaver–Burk or double-reciprocal plot with different compound concentrations yielded an intercept at the Y-axis, suggesting that 23R is a competitive inhibitor similar to ML188 (1) (Figure C, D bottom panel). Buy our T-shirts for the lowerst prices you can find!!! Overall, the enzymatic kinetic studies confirmed that compound 23R is a noncovalent inhibitor of SARS-CoV-2 Mpro.""" | |
text2 = """ | |
Apple Inc. is an American multinational technology company headquartered in Cupertino, California. Apple is the world's largest technology company by revenue, with US$394.3 billion in 2022 revenue. As of March 2023, Apple is the world's biggest company by market capitalization. As of June 2022, Apple is the fourth-largest personal computer vendor by unit sales and the second-largest mobile phone manufacturer in the world. It is considered one of the Big Five American information technology companies, alongside Alphabet (parent company of Google), Amazon, Meta Platforms, and Microsoft. | |
Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014. | |
Apple was founded as Apple Computer Company on April 1, 1976, by Steve Wozniak, Steve Jobs (1955–2011) and Ronald Wayne to develop and sell Wozniak's Apple I personal computer. It was incorporated by Jobs and Wozniak as Apple Computer, Inc. in 1977. The company's second computer, the Apple II, became a best seller and one of the first mass-produced microcomputers. Apple went public in 1980 to instant financial success. The company developed computers featuring innovative graphical user interfaces, including the 1984 original Macintosh, announced that year in a critically acclaimed advertisement called "1984". By 1985, the high cost of its products, and power struggles between executives, caused problems. Wozniak stepped back from Apple and pursued other ventures, while Jobs resigned and founded NeXT, taking some Apple employees with him. Order today and get 30% discount! | |
""" | |
open_ie_examples = [ | |
[ | |
f"Clean the following text extracted from the web matching not relevant parts:", | |
text1, | |
0.5, | |
False | |
], | |
[ | |
f"Clean the following text extracted from the web matching not relevant parts:", | |
text2, | |
0.5, | |
False | |
]] | |
def process(prompt, text, treshold=0.5, label = "match"): | |
""" | |
Processes text by preparing prompt and adjusting indices. | |
Args: | |
text (str): The text to process | |
prompt (str): The prompt to prepend to the text | |
Returns: | |
list: A list of dicts with adjusted spans and scores | |
""" | |
# Concatenate text and prompt for full input | |
input_ = f"{prompt}\n{text}" | |
results = transformers_pipeline(input_) # Run NLP on full input | |
processed_results = [] | |
prompt_length = len(prompt) # Get prompt length | |
for result in results: | |
# check whether score is higher than treshold | |
if result['score']<treshold: | |
continue | |
# Adjust indices by subtracting prompt length | |
start = result['start'] - prompt_length | |
# If indexes belongs to the prompt - continue | |
if start<0: | |
continue | |
end = result['end'] - prompt_length | |
# Extract span from original text using adjusted indices | |
span = text[start:end] | |
# Create processed result dict | |
processed_result = { | |
'span': span, | |
'start': start, | |
'end': end, | |
'score': result['score'], | |
'entity': label | |
} | |
processed_results.append(processed_result) | |
output = {"text": text, "entities": processed_results} | |
return output | |
with gr.Blocks(title="Text Cleaning") as text_cleaning_interface: | |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your prompt here") | |
input_text = gr.Textbox(label="Text input", placeholder="Enter your text here") | |
threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold", info="Lower the threshold to increase how many entities get predicted.") | |
output = [gr.HighlightedText(label="Predicted Entities")] | |
submit_btn = gr.Button("Submit") | |
examples = gr.Examples( | |
open_ie_examples, | |
fn=process, | |
inputs=[prompt, input_text, threshold], | |
outputs=output, | |
cache_examples=True | |
) | |
theme=gr.themes.Base() | |
input_text.submit(fn=process, inputs=[prompt, input_text, threshold], outputs=output) | |
prompt.submit(fn=process, inputs=[prompt, input_text, threshold], outputs=output) | |
threshold.release(fn=process, inputs=[prompt, input_text, threshold], outputs=output) | |
submit_btn.click(fn=process, inputs=[prompt, input_text, threshold,], outputs=output) | |
if __name__ == "__main__": | |
text_cleaning_interface.launch() |