Update app.py
Browse files
app.py
CHANGED
|
@@ -27,23 +27,23 @@ class Detect():
|
|
| 27 |
import langid
|
| 28 |
result: tuple[str, float] = langid.classify(self.text)
|
| 29 |
langcode, langecode_probabilities = result
|
| 30 |
-
return langcode, round(number=langecode_probabilities * 10, ndigits=2)
|
| 31 |
|
| 32 |
def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, str]:
|
| 33 |
"""
|
| 34 |
-
Detects the
|
| 35 |
|
| 36 |
Parameters:
|
| 37 |
input_text (str): The source text to be translated
|
| 38 |
|
| 39 |
Returns:
|
| 40 |
-
|
| 41 |
-
detected_text(str): The
|
| 42 |
-
confidence(
|
| 43 |
|
| 44 |
Example:
|
| 45 |
>>> detect_language("Hello world")
|
| 46 |
-
|
| 47 |
"""
|
| 48 |
detectinstance = Detect(input_text)
|
| 49 |
detections = []
|
|
@@ -60,30 +60,24 @@ def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, st
|
|
| 60 |
|
| 61 |
with gr.Blocks() as interface:
|
| 62 |
gr.Markdown("### Language Detection with Gradio API and MCP Server")
|
| 63 |
-
input_text = gr.Textbox(label="Enter text to detect:", placeholder="Type/copy text here, maximum 512
|
| 64 |
autofocus=True, submit_btn='Detect Language', max_length=512)
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
# confidence = gr.Textbox(label="Confidence:", placeholder="Display field for confidence score", interactive=False, buttons=["copy"], lines=1)
|
| 68 |
-
# execution_time = gr.Textbox(label="Execution time:", placeholder="Display field for execution time", interactive=False, lines=1)
|
| 69 |
-
used_libraries = gr.CheckboxGroup(choices=libraries, label="Detection libraries", info="Detection libraries")
|
| 70 |
dataframe = gr.Dataframe(
|
| 71 |
-
headers=["Language", "Score"],
|
| 72 |
datatype=["str", "float"], # type: array
|
| 73 |
row_count=len(libraries),
|
| 74 |
column_count=2,
|
| 75 |
column_limits=(2, 3),
|
|
|
|
| 76 |
)
|
| 77 |
input_text.submit(
|
| 78 |
fn=detect_language,
|
| 79 |
inputs=[input_text, used_libraries],
|
| 80 |
outputs=[dataframe]
|
| 81 |
)
|
| 82 |
-
|
| 83 |
-
# fn=detect_language,
|
| 84 |
-
# inputs=[input_text, used_libraries],
|
| 85 |
-
# outputs=[detected_text, confidence, execution_time]
|
| 86 |
-
# )
|
| 87 |
if __name__ == "__main__":
|
| 88 |
interface.launch(mcp_server=True, footer_links=["api", "settings"])
|
| 89 |
# interface.queue().launch(server_name="0.0.0.0", show_error=True, server_port=7860, mcp_server=True)
|
|
|
|
| 27 |
import langid
|
| 28 |
result: tuple[str, float] = langid.classify(self.text)
|
| 29 |
langcode, langecode_probabilities = result
|
| 30 |
+
return langcode, abs(round(number=langecode_probabilities * 10, ndigits=2))
|
| 31 |
|
| 32 |
def detect_language(input_text: str, used_libraries: list[str]) -> tuple[str, str]:
|
| 33 |
"""
|
| 34 |
+
Detects the language of the input text.
|
| 35 |
|
| 36 |
Parameters:
|
| 37 |
input_text (str): The source text to be translated
|
| 38 |
|
| 39 |
Returns:
|
| 40 |
+
list:
|
| 41 |
+
detected_text(str): The language code of the input text
|
| 42 |
+
confidence(float): The confidence score as float
|
| 43 |
|
| 44 |
Example:
|
| 45 |
>>> detect_language("Hello world")
|
| 46 |
+
["en", 1.0]
|
| 47 |
"""
|
| 48 |
detectinstance = Detect(input_text)
|
| 49 |
detections = []
|
|
|
|
| 60 |
|
| 61 |
with gr.Blocks() as interface:
|
| 62 |
gr.Markdown("### Language Detection with Gradio API and MCP Server")
|
| 63 |
+
input_text = gr.Textbox(label="Enter text to detect:", placeholder="Type/copy text here, maximum 512 characters",
|
| 64 |
autofocus=True, submit_btn='Detect Language', max_length=512)
|
| 65 |
+
with gr.Row(variant="compact"):
|
| 66 |
+
used_libraries = gr.CheckboxGroup(choices=libraries, value=libraries, label="Detection libraries", info="Detection libraries", show_select_all=True)
|
|
|
|
|
|
|
|
|
|
| 67 |
dataframe = gr.Dataframe(
|
| 68 |
+
headers=["Language code", "Score"],
|
| 69 |
datatype=["str", "float"], # type: array
|
| 70 |
row_count=len(libraries),
|
| 71 |
column_count=2,
|
| 72 |
column_limits=(2, 3),
|
| 73 |
+
label='Language detection dataframe'
|
| 74 |
)
|
| 75 |
input_text.submit(
|
| 76 |
fn=detect_language,
|
| 77 |
inputs=[input_text, used_libraries],
|
| 78 |
outputs=[dataframe]
|
| 79 |
)
|
| 80 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
if __name__ == "__main__":
|
| 82 |
interface.launch(mcp_server=True, footer_links=["api", "settings"])
|
| 83 |
# interface.queue().launch(server_name="0.0.0.0", show_error=True, server_port=7860, mcp_server=True)
|