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()