Spaces:
Runtime error
Runtime error
File size: 2,579 Bytes
f291881 6887849 de5713b 0ae0889 de5713b 0ae0889 de5713b f291881 de5713b f291881 de5713b f291881 de5713b f291881 de5713b f291881 de5713b f291881 6887849 f291881 de5713b f291881 de5713b f291881 de5713b f291881 de5713b f291881 de5713b f291881 de5713b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import gradio as gr
from models.space_a import summarize_question
from models.space_b import generate_mentalqa_answer
from models.space_er import extract_entities
# CSS styling for RTL layout
css = """
body {
direction: rtl;
text-align: right;
}
.container-box {
padding-top: 20px !important;
margin-top: 0 !important;
text-align: right;
}
.output-box {
text-align: right;
direction: rtl;
}
"""
# Task handler
def analyze_text(text, task, classification_type):
if not text.strip():
return "ุงูุฑุฌุงุก ุฅุฏุฎุงู ูุต ููุชุญููู."
try:
if task == "classification":
return generate_mentalqa_answer(text)
elif task == "summarization":
return summarize_question(text)
elif task == "entity_recognition":
return extract_entities(text)
else:
return "โ ุงูู
ูู
ุฉ ุบูุฑ ู
ุฏุนูู
ุฉ ุญุงููุงู."
except Exception as e:
return f"โ ุญุฏุซ ุฎุทุฃ ุฃุซูุงุก ุงูู
ุนุงูุฌุฉ: {str(e)}"
# Dynamic UI visibility for classification type dropdown
def update_ui(task):
return gr.update(visible=(task == "classification"))
# Gradio interface
with gr.Blocks(css=css, title="ู
ูุตุฉ ุงูุตุญุฉ ุงูููุณูุฉ") as demo:
with gr.Column(elem_classes=["container-box"]):
gr.Markdown("## ๐ง ุชุฌุฑุจุฉ ู
ูุตุฉ ุงูุตุญุฉ ุงูููุณูุฉ")
task_selector = gr.Dropdown(
choices=[
("ุชุตููู ุงูุฃุณุฆูุฉ ูุงูุฃุฌูุจุฉ", "classification"),
("ุชูุฎูุต ุงููุตูุต", "summarization"),
("ุงูุชุนุฑู ุนูู ุงูููุงูุงุช", "entity_recognition")
],
label="ุงุฎุชูุงุฑ ููุน ุงูู
ูู
ุฉ",
value="classification"
)
user_input = gr.Textbox(
placeholder="ุฃุฏุฎู ุงููุต ููุง ูุชุญูููู...",
lines=4,
show_label=False
)
classification_dropdown = gr.Dropdown(
choices=["ุชุตููู ุณุคุงู", "ุชุตููู ุฅุฌุงุจุฉ"],
label="ููุน ุงูุชุตููู",
visible=True
)
submit_btn = gr.Button("ุงุจุฏุฃ ุงูุชุญููู")
output = gr.Textbox(
label="ุงููุชูุฌุฉ",
elem_classes=["output-box"]
)
# Events
task_selector.change(fn=update_ui, inputs=task_selector, outputs=classification_dropdown)
submit_btn.click(fn=analyze_text, inputs=[user_input, task_selector, classification_dropdown], outputs=output)
if __name__ == "__main__":
demo.launch()
|