Spaces:
Running
Running
Upload 2 files
Browse files
app.py
CHANGED
|
@@ -602,7 +602,7 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 602 |
)
|
| 603 |
single_output = gr.JSON(label="Embedding Result")
|
| 604 |
single_btn = gr.Button("Generate Embedding", variant="primary")
|
| 605 |
-
single_btn.click(fn=get_embedding, inputs=text_input, outputs=single_output)
|
| 606 |
|
| 607 |
with gr.Tab("π¦ Batch Embedding"):
|
| 608 |
gr.Markdown("Generate embeddings untuk multiple teks sekaligus")
|
|
@@ -613,7 +613,7 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 613 |
)
|
| 614 |
batch_output = gr.JSON(label="Embeddings Result")
|
| 615 |
batch_btn = gr.Button("Generate Embeddings", variant="primary")
|
| 616 |
-
batch_btn.click(fn=get_embeddings_batch, inputs=batch_input, outputs=batch_output)
|
| 617 |
|
| 618 |
with gr.Tab("π Similarity Check"):
|
| 619 |
gr.Markdown("Hitung kemiripan semantik antara dua teks")
|
|
@@ -622,7 +622,7 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 622 |
sim_text2 = gr.Textbox(label="Text 2", placeholder="Teks kedua...", lines=2)
|
| 623 |
sim_output = gr.JSON(label="Similarity Result")
|
| 624 |
sim_btn = gr.Button("Calculate Similarity", variant="primary")
|
| 625 |
-
sim_btn.click(fn=calculate_similarity, inputs=[sim_text1, sim_text2], outputs=sim_output)
|
| 626 |
|
| 627 |
with gr.Tab("πΎ Database (Supabase)"):
|
| 628 |
gr.Markdown("### Supabase Cache Operations")
|
|
@@ -632,14 +632,14 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 632 |
with gr.Row():
|
| 633 |
db_check_btn = gr.Button("π Check Connection", variant="secondary")
|
| 634 |
db_check_output = gr.JSON(label="Connection Status")
|
| 635 |
-
db_check_btn.click(fn=db_check_connection, outputs=db_check_output)
|
| 636 |
|
| 637 |
gr.Markdown("---")
|
| 638 |
|
| 639 |
gr.Markdown("#### Get All Cached Embeddings")
|
| 640 |
db_all_btn = gr.Button("π₯ Get All Embeddings", variant="primary")
|
| 641 |
db_all_output = gr.JSON(label="All Embeddings")
|
| 642 |
-
db_all_btn.click(fn=db_get_all_embeddings, outputs=db_all_output)
|
| 643 |
|
| 644 |
gr.Markdown("---")
|
| 645 |
|
|
@@ -649,7 +649,7 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 649 |
db_hash_input = gr.Textbox(label="Content Hash", placeholder="abc123...")
|
| 650 |
db_get_btn = gr.Button("π Get Embedding", variant="primary")
|
| 651 |
db_get_output = gr.JSON(label="Embedding Result")
|
| 652 |
-
db_get_btn.click(fn=db_get_embedding, inputs=[db_nim_input, db_hash_input], outputs=db_get_output)
|
| 653 |
|
| 654 |
with gr.Tab("π€ LLM Analysis (Gemini)"):
|
| 655 |
gr.Markdown("### Analisis Kemiripan dengan LLM")
|
|
@@ -658,7 +658,7 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 658 |
with gr.Row():
|
| 659 |
llm_check_btn = gr.Button("π Check Gemini Status", variant="secondary")
|
| 660 |
llm_check_output = gr.JSON(label="Gemini Status")
|
| 661 |
-
llm_check_btn.click(fn=llm_check_status, outputs=llm_check_output)
|
| 662 |
|
| 663 |
gr.Markdown("---")
|
| 664 |
|
|
@@ -676,7 +676,8 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 676 |
llm_simple_btn.click(
|
| 677 |
fn=llm_analyze_simple,
|
| 678 |
inputs=[llm_judul1, llm_judul2, llm_metode1, llm_metode2],
|
| 679 |
-
outputs=llm_simple_output
|
|
|
|
| 680 |
)
|
| 681 |
|
| 682 |
gr.Markdown("---")
|
|
@@ -703,7 +704,8 @@ with gr.Blocks(title="Semantic Embedding API") as demo:
|
|
| 703 |
llm_full_btn.click(
|
| 704 |
fn=llm_analyze_pair,
|
| 705 |
inputs=[llm_proposal1, llm_proposal2, llm_use_cache],
|
| 706 |
-
outputs=llm_full_output
|
|
|
|
| 707 |
)
|
| 708 |
|
| 709 |
gr.Markdown("""
|
|
@@ -750,6 +752,13 @@ const dataResponse = await fetch(`YOUR_SPACE_URL/gradio_api/call/db_get_all_embe
|
|
| 750 |
|
| 751 |
gr.Markdown("---")
|
| 752 |
gr.Markdown("*Dibuat untuk Monitoring Proposal Skripsi KK E - UNIKOM*")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 753 |
|
| 754 |
# Launch dengan API enabled
|
| 755 |
demo.launch()
|
|
|
|
| 602 |
)
|
| 603 |
single_output = gr.JSON(label="Embedding Result")
|
| 604 |
single_btn = gr.Button("Generate Embedding", variant="primary")
|
| 605 |
+
single_btn.click(fn=get_embedding, inputs=text_input, outputs=single_output, api_name="get_embedding")
|
| 606 |
|
| 607 |
with gr.Tab("π¦ Batch Embedding"):
|
| 608 |
gr.Markdown("Generate embeddings untuk multiple teks sekaligus")
|
|
|
|
| 613 |
)
|
| 614 |
batch_output = gr.JSON(label="Embeddings Result")
|
| 615 |
batch_btn = gr.Button("Generate Embeddings", variant="primary")
|
| 616 |
+
batch_btn.click(fn=get_embeddings_batch, inputs=batch_input, outputs=batch_output, api_name="get_embeddings_batch")
|
| 617 |
|
| 618 |
with gr.Tab("π Similarity Check"):
|
| 619 |
gr.Markdown("Hitung kemiripan semantik antara dua teks")
|
|
|
|
| 622 |
sim_text2 = gr.Textbox(label="Text 2", placeholder="Teks kedua...", lines=2)
|
| 623 |
sim_output = gr.JSON(label="Similarity Result")
|
| 624 |
sim_btn = gr.Button("Calculate Similarity", variant="primary")
|
| 625 |
+
sim_btn.click(fn=calculate_similarity, inputs=[sim_text1, sim_text2], outputs=sim_output, api_name="calculate_similarity")
|
| 626 |
|
| 627 |
with gr.Tab("πΎ Database (Supabase)"):
|
| 628 |
gr.Markdown("### Supabase Cache Operations")
|
|
|
|
| 632 |
with gr.Row():
|
| 633 |
db_check_btn = gr.Button("π Check Connection", variant="secondary")
|
| 634 |
db_check_output = gr.JSON(label="Connection Status")
|
| 635 |
+
db_check_btn.click(fn=db_check_connection, outputs=db_check_output, api_name="db_check_connection")
|
| 636 |
|
| 637 |
gr.Markdown("---")
|
| 638 |
|
| 639 |
gr.Markdown("#### Get All Cached Embeddings")
|
| 640 |
db_all_btn = gr.Button("π₯ Get All Embeddings", variant="primary")
|
| 641 |
db_all_output = gr.JSON(label="All Embeddings")
|
| 642 |
+
db_all_btn.click(fn=db_get_all_embeddings, outputs=db_all_output, api_name="db_get_all_embeddings")
|
| 643 |
|
| 644 |
gr.Markdown("---")
|
| 645 |
|
|
|
|
| 649 |
db_hash_input = gr.Textbox(label="Content Hash", placeholder="abc123...")
|
| 650 |
db_get_btn = gr.Button("π Get Embedding", variant="primary")
|
| 651 |
db_get_output = gr.JSON(label="Embedding Result")
|
| 652 |
+
db_get_btn.click(fn=db_get_embedding, inputs=[db_nim_input, db_hash_input], outputs=db_get_output, api_name="db_get_embedding")
|
| 653 |
|
| 654 |
with gr.Tab("π€ LLM Analysis (Gemini)"):
|
| 655 |
gr.Markdown("### Analisis Kemiripan dengan LLM")
|
|
|
|
| 658 |
with gr.Row():
|
| 659 |
llm_check_btn = gr.Button("π Check Gemini Status", variant="secondary")
|
| 660 |
llm_check_output = gr.JSON(label="Gemini Status")
|
| 661 |
+
llm_check_btn.click(fn=llm_check_status, outputs=llm_check_output, api_name="llm_check_status")
|
| 662 |
|
| 663 |
gr.Markdown("---")
|
| 664 |
|
|
|
|
| 676 |
llm_simple_btn.click(
|
| 677 |
fn=llm_analyze_simple,
|
| 678 |
inputs=[llm_judul1, llm_judul2, llm_metode1, llm_metode2],
|
| 679 |
+
outputs=llm_simple_output,
|
| 680 |
+
api_name="llm_analyze_simple"
|
| 681 |
)
|
| 682 |
|
| 683 |
gr.Markdown("---")
|
|
|
|
| 704 |
llm_full_btn.click(
|
| 705 |
fn=llm_analyze_pair,
|
| 706 |
inputs=[llm_proposal1, llm_proposal2, llm_use_cache],
|
| 707 |
+
outputs=llm_full_output,
|
| 708 |
+
api_name="llm_analyze_pair"
|
| 709 |
)
|
| 710 |
|
| 711 |
gr.Markdown("""
|
|
|
|
| 752 |
|
| 753 |
gr.Markdown("---")
|
| 754 |
gr.Markdown("*Dibuat untuk Monitoring Proposal Skripsi KK E - UNIKOM*")
|
| 755 |
+
|
| 756 |
+
# Hidden API-only endpoints (tidak tampil di UI, tapi bisa diakses via API)
|
| 757 |
+
with gr.Row(visible=False):
|
| 758 |
+
api_save_input = gr.Textbox()
|
| 759 |
+
api_save_output = gr.JSON()
|
| 760 |
+
api_save_btn = gr.Button()
|
| 761 |
+
api_save_btn.click(fn=db_save_embedding, inputs=api_save_input, outputs=api_save_output, api_name="db_save_embedding")
|
| 762 |
|
| 763 |
# Launch dengan API enabled
|
| 764 |
demo.launch()
|