update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from openai import OpenAI
|
|
7 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
8 |
|
9 |
# Function to process the input and generate the output
|
10 |
-
def process_query(wiki_page, embed_dim, query, api_key=None
|
11 |
model_mapping = {
|
12 |
"Arabic-mpnet-base-all-nli-triplet": "Omartificial-Intelligence-Space/Arabic-mpnet-base-all-nli-triplet",
|
13 |
"Arabic-all-nli-triplet-Matryoshka": "Omartificial-Intelligence-Space/Arabic-all-nli-triplet-Matryoshka",
|
@@ -63,35 +63,32 @@ def process_query(wiki_page, embed_dim, query, api_key=None, mode="OpenAI"):
|
|
63 |
|
64 |
return "\n\n".join([f"Model: {model_name}\nResponse: {response}" for model_name, response in responses.items()])
|
65 |
|
66 |
-
|
67 |
-
wiki_page_input = gr.Textbox(label="Wikipedia Page (in Arabic)")
|
68 |
-
query_input = gr.Textbox(label="Query (in Arabic)")
|
69 |
-
api_key_input = gr.Textbox(label="OpenAI API Key", type="password", visible=False)
|
70 |
-
|
71 |
-
embed_dim_choice = gr.Dropdown(
|
72 |
-
|
73 |
-
|
74 |
-
)
|
75 |
-
|
76 |
-
mode_choice = gr.Radio(
|
77 |
-
|
78 |
-
|
79 |
-
)
|
80 |
-
|
81 |
-
output_text = gr.Textbox(label="Output")
|
82 |
-
|
83 |
-
def on_mode_change(mode):
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
mode_choice.change(on_mode_change, inputs=mode_choice, outputs=api_key_input)
|
90 |
-
|
91 |
-
gr.
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
title="Arabic Wiki RAG",
|
96 |
-
description="Choose a Wikipedia page, embedding model, and dimension to answer a query in Arabic."
|
97 |
-
).launch()
|
|
|
7 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
8 |
|
9 |
# Function to process the input and generate the output
|
10 |
+
def process_query(wiki_page, embed_dim, query, mode, api_key=None):
|
11 |
model_mapping = {
|
12 |
"Arabic-mpnet-base-all-nli-triplet": "Omartificial-Intelligence-Space/Arabic-mpnet-base-all-nli-triplet",
|
13 |
"Arabic-all-nli-triplet-Matryoshka": "Omartificial-Intelligence-Space/Arabic-all-nli-triplet-Matryoshka",
|
|
|
63 |
|
64 |
return "\n\n".join([f"Model: {model_name}\nResponse: {response}" for model_name, response in responses.items()])
|
65 |
|
66 |
+
with gr.Blocks() as demo:
|
67 |
+
wiki_page_input = gr.Textbox(label="Wikipedia Page (in Arabic)")
|
68 |
+
query_input = gr.Textbox(label="Query (in Arabic)")
|
69 |
+
api_key_input = gr.Textbox(label="OpenAI API Key", type="password", visible=False)
|
70 |
+
|
71 |
+
embed_dim_choice = gr.Dropdown(
|
72 |
+
choices=[768, 512, 256, 128, 64],
|
73 |
+
label="Embedding Dimension"
|
74 |
+
)
|
75 |
+
|
76 |
+
mode_choice = gr.Radio(
|
77 |
+
choices=["OpenAI", "OpenSource"],
|
78 |
+
label="Choose Mode"
|
79 |
+
)
|
80 |
+
|
81 |
+
output_text = gr.Textbox(label="Output")
|
82 |
+
|
83 |
+
def on_mode_change(mode):
|
84 |
+
if mode == "OpenAI":
|
85 |
+
api_key_input.visible = True
|
86 |
+
else:
|
87 |
+
api_key_input.visible = False
|
88 |
+
|
89 |
+
mode_choice.change(on_mode_change, inputs=mode_choice, outputs=api_key_input)
|
90 |
+
|
91 |
+
submit_button = gr.Button("Submit")
|
92 |
+
submit_button.click(process_query, inputs=[wiki_page_input, embed_dim_choice, query_input, mode_choice, api_key_input], outputs=output_text)
|
93 |
+
|
94 |
+
demo.launch()
|
|
|
|
|
|