Skip to content
Snippets Groups Projects
Commit d9c2b536 authored by Zhili Wang's avatar Zhili Wang
Browse files

update mono

parent 1a533438
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
import gradio as gr import gradio as gr
import json import json
import sys import sys
import os import os
from use_bio_html import run from use_bio_html import run
...@@ -12,7 +12,7 @@ HTML_BASE = """<div style="padding-left: 5px; padding-right: 0px;"> ...@@ -12,7 +12,7 @@ HTML_BASE = """<div style="padding-left: 5px; padding-right: 0px;">
</style> </style>
<div style="font-size:20px;display:flex;"> <div style="font-size:20px;display:flex;">
<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;&nbsp;&nbsp;</strong> <strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong>
<strong style="word-wrap:break-word;padding: 0px 50px 25px 60px;text-align: center;">Definition</strong> <strong style="word-wrap:break-word;padding: 0px 50px 25px 60px;text-align: center;">Definition</strong>
</div> </div>
<ol start="1" style="color:grey"> <ol start="1" style="color:grey">
...@@ -20,20 +20,18 @@ HTML_BASE = """<div style="padding-left: 5px; padding-right: 0px;"> ...@@ -20,20 +20,18 @@ HTML_BASE = """<div style="padding-left: 5px; padding-right: 0px;">
HTML_TEMPLATE = """ HTML_TEMPLATE = """
<li style="font-size:20px;display:flex;" class="textspan svelte-ju12zg hl "> <li style="font-size:20px;display:flex;" class="textspan svelte-ju12zg hl ">
<a href="http://parts.igem.org/Part:{name}" target="_blank"><u>{name}</u></a> <a href="http://parts.igem.org/Part:{name}" target="_blank" style="width:128px;"><u>{name}</u></a>
<div style="word-wrap:break-word;padding: 0px 50px 25px 50px">{definition}</div> <div style="word-wrap:break-word;padding: 0px 50px 25px 50px">{definition}</div>
</li> </li>
""" """
with open("target_words.txt") as f: with open("target_words.txt") as f:
word_list=f.readlines() word_list = f.readlines()
with open("train.json") as f: with open("desc_pre.json") as f:
word_desriptions=json.load(f) word_desriptions = json.load(f)
def calcolor(p): def calcolor(p):
...@@ -45,14 +43,18 @@ def calcolor(p): ...@@ -45,14 +43,18 @@ def calcolor(p):
def predict(text): def predict(text):
res_index,res_score,res_name=run(text) res_index, res_score, res_name = run(text)
html_res = ( html_res = (
HTML_BASE HTML_BASE
+ "".join( + "".join(
[ [
HTML_TEMPLATE.format( HTML_TEMPLATE.format(
color=calcolor(1-i/len(res_index)), definition=word_desriptions[res_index[i]]["definitions"], name=word_list[i] color=calcolor(1 - i / len(res_index)),
definition=word_desriptions[word_list[res_index[i]].strip("\n")],
name=word_list[
res_index[i]
], # .ljust(13,'\n').replace('\n','&nbsp;')
) )
for i in range(len(res_index)) for i in range(len(res_index))
] ]
...@@ -62,9 +64,11 @@ def predict(text): ...@@ -62,9 +64,11 @@ def predict(text):
return html_res return html_res
with gr.Blocks(title="Reverse Dictonary for Biobricks") as demo: with gr.Blocks(title="Ask NOX") as demo:
gr.Markdown("# Welcome to use Reverse Dictonary for Biobricks") gr.Markdown("# Welcome to use Ask NOX!")
input = gr.Textbox(label="", placeholder="Please type what you want...") input = gr.Textbox(
label="", placeholder="Please type the description of the biobricks you want..."
)
greet_btn = gr.Button("Look up") greet_btn = gr.Button("Look up")
output = gr.HTML() output = gr.HTML()
greet_btn.click(fn=predict, inputs=input, outputs=output, api_name="predict") greet_btn.click(fn=predict, inputs=input, outputs=output, api_name="predict")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment