Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import gradio as gr
|
|
4 |
import os
|
5 |
import pandas as pd
|
6 |
from datasets import load_dataset
|
7 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
8 |
from datasets import Features, Value
|
9 |
import plotly.express as px
|
10 |
|
@@ -16,7 +16,7 @@ Secret_token = os.getenv('HF_token')
|
|
16 |
dataset = load_dataset("FDSRashid/embed_matn", token = Secret_token)
|
17 |
books = load_dataset('FDSRashid/Hadith_info', data_files='Books.csv', token=Secret_token)['train'].to_pandas()
|
18 |
df = dataset["train"].to_pandas()
|
19 |
-
|
20 |
|
21 |
dataset = load_dataset("FDSRashid/hadith_info", data_files = 'All_Matns.csv',token = Secret_token, features = features)
|
22 |
matn_info = dataset['train'].to_pandas()
|
@@ -39,12 +39,12 @@ joined_df = pd.merge(matn_info,df[cols_to_use],left_index=True, right_index=True
|
|
39 |
df = joined_df.copy()
|
40 |
taraf_max = np.max(df['taraf_ID'].unique())
|
41 |
|
42 |
-
def plot_similarity_score(taraf_num):
|
43 |
taraf_df = df[df['taraf_ID']== taraf_num]
|
44 |
taraf_df['Number'] = np.arange(len(taraf_df))
|
45 |
embed_taraf = taraf_df['embed'].to_list()
|
46 |
-
cos_score =
|
47 |
-
fig = px.imshow(cos_score)
|
48 |
matr = cos_score
|
49 |
rows, cols = matr.shape
|
50 |
mask = np.tril(np.ones((rows, cols), dtype=bool), k=-1)
|
@@ -55,6 +55,7 @@ def plot_similarity_score(taraf_num):
|
|
55 |
|
56 |
with gr.Blocks() as demo:
|
57 |
taraf_number = gr.Slider(1,taraf_max , value=10000, label="Taraf", info="Choose the Taraf to Input", step = 1)
|
|
|
58 |
btn = gr.Button('Submit')
|
59 |
btn.click(fn = plot_similarity_score, inputs = [taraf_number], outputs = [gr.Plot(),gr.Plot(), gr.DataFrame()])
|
60 |
demo.launch()
|
|
|
4 |
import os
|
5 |
import pandas as pd
|
6 |
from datasets import load_dataset
|
7 |
+
from sklearn.metrics.pairwise import cosine_similarity, pairwise_distance
|
8 |
from datasets import Features, Value
|
9 |
import plotly.express as px
|
10 |
|
|
|
16 |
dataset = load_dataset("FDSRashid/embed_matn", token = Secret_token)
|
17 |
books = load_dataset('FDSRashid/Hadith_info', data_files='Books.csv', token=Secret_token)['train'].to_pandas()
|
18 |
df = dataset["train"].to_pandas()
|
19 |
+
choice = ['cityblock', 'cosine', 'euclidean', 'l1', 'l2', 'manhattan', 'canberra', 'chebyshev']
|
20 |
|
21 |
dataset = load_dataset("FDSRashid/hadith_info", data_files = 'All_Matns.csv',token = Secret_token, features = features)
|
22 |
matn_info = dataset['train'].to_pandas()
|
|
|
39 |
df = joined_df.copy()
|
40 |
taraf_max = np.max(df['taraf_ID'].unique())
|
41 |
|
42 |
+
def plot_similarity_score(taraf_num, metr):
|
43 |
taraf_df = df[df['taraf_ID']== taraf_num]
|
44 |
taraf_df['Number'] = np.arange(len(taraf_df))
|
45 |
embed_taraf = taraf_df['embed'].to_list()
|
46 |
+
cos_score = pairwise_distance(embed_taraf, metric = metr)
|
47 |
+
fig = px.imshow(cos_score, color_continuous_scale='plasma_r')
|
48 |
matr = cos_score
|
49 |
rows, cols = matr.shape
|
50 |
mask = np.tril(np.ones((rows, cols), dtype=bool), k=-1)
|
|
|
55 |
|
56 |
with gr.Blocks() as demo:
|
57 |
taraf_number = gr.Slider(1,taraf_max , value=10000, label="Taraf", info="Choose the Taraf to Input", step = 1)
|
58 |
+
metric = gr.Dropdown(choices = choice, value = 'cosine', label = 'Variable to Display', info = 'Choose the variable to visualize.')
|
59 |
btn = gr.Button('Submit')
|
60 |
btn.click(fn = plot_similarity_score, inputs = [taraf_number], outputs = [gr.Plot(),gr.Plot(), gr.DataFrame()])
|
61 |
demo.launch()
|