Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,30 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import random
|
| 4 |
from diffusers import DiffusionPipeline
|
|
@@ -143,4 +169,5 @@ with gr.Blocks(css=css) as demo:
|
|
| 143 |
outputs = [result]
|
| 144 |
)
|
| 145 |
|
| 146 |
-
demo.queue().launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import spacy
|
| 3 |
+
|
| 4 |
+
# 加载 spaCy 的英语模型
|
| 5 |
+
nlp = spacy.load("en_core_web_sm")
|
| 6 |
+
|
| 7 |
+
def highlight_nouns(text):
|
| 8 |
+
doc = nlp(text)
|
| 9 |
+
highlighted_text = [(token.text, "noun") if token.pos_ == "NOUN" else token.text for token in doc]
|
| 10 |
+
nouns = [token.text for token in doc if token.pos_ == "NOUN"]
|
| 11 |
+
return highlighted_text, ', '.join(nouns)
|
| 12 |
+
|
| 13 |
+
# 创建 Gradio 接口
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
input_text = gr.Textbox(label="输入文本")
|
| 16 |
+
highlighted_text = gr.HighlightedText(label="高亮的名词")
|
| 17 |
+
output_nouns = gr.Textbox(label="名词列表")
|
| 18 |
+
|
| 19 |
+
input_text.change(highlight_nouns, inputs=input_text, outputs=[highlighted_text, output_nouns])
|
| 20 |
+
|
| 21 |
+
demo.launch()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
'''
|
| 27 |
+
import gradio as gr
|
| 28 |
import numpy as np
|
| 29 |
import random
|
| 30 |
from diffusers import DiffusionPipeline
|
|
|
|
| 169 |
outputs = [result]
|
| 170 |
)
|
| 171 |
|
| 172 |
+
demo.queue().launch()
|
| 173 |
+
'''
|