Spaces:
Sleeping
Sleeping
Asanaly commited on
Update app.py
Browse files35 unmodified lines363738393940414142434445464546474849505152535455565748495051525354555657585960616263646563666765686967707172737475767735 unmodified lines return results
# ============================# 3. Түсті HTML шығару# 3. Атауларды текстпен шығару# ============================def highlight_ner(text):def format_ner(text): entities = predict_ner(text) if not entities: return "Атаулар табылған жоқ"
colored_text = text output_dict = {"PER": [], "ORG": [], "LOC": []} for word, label in entities: color = "" if label.startswith("PER"): color = "red" elif label.startswith("ORG"): color = "blue" elif label.startswith("LOC"): color = "green" # Мәтіндегі сөзді HTML span тегпен орау colored_text = colored_text.replace(word, f"<span style='color:{color}; font-weight:bold'>{word}</span>") return colored_text if label.endswith("PER"): output_dict["PER"].append(word) elif label.endswith("ORG"): output_dict["ORG"].append(word) elif label.endswith("LOC"): output_dict["LOC"].append(word) # Бір қатарға қосып шығару output_text = "" for key, words in output_dict.items(): if words: output_text += f"{key}: {' '.join(words)}\n" return output_text.strip()
# ============================# 4. Gradio интерфейсі# ============================iface = gr.Interface( fn=highlight_ner, fn=format_ner, inputs=gr.Textbox(lines=10, placeholder="Қазақ мәтінін осында енгізіңіз..."), outputs=gr.HTML(label="Анықталған атаулар"), outputs=gr.Textbox(label="Анықталған атаулар"), title="Қазақ тіліндегі NER", description="PER – адам, ORG – ұйым, LOC – орын. Атаулар мәтінде түспен ерекшеленеді." description="PER – адам, ORG – ұйым, LOC – орын. Атаулар қарапайым текстпен шығарылады.")
# ============================# 5. Іске қосу# ============================iface.launch()
app.py+21-17