Tyler Burns commited on
Commit
70dcacb
1 Parent(s): 7f8b789

making link clickable attempt 1

Browse files
Files changed (2) hide show
  1. app.py +6 -0
  2. flycheck_app.py +0 -75
app.py CHANGED
@@ -71,5 +71,11 @@ dat['body'] = [re.sub('<br>', ' ', i) for i in dat['body']]
71
  # Instructions
72
  st.caption('Click on the table and press ctrl+f (or command+f for mac) to search it')
73
 
 
 
 
 
 
 
74
  # Place a table under the plot
75
  st.dataframe(dat)
 
71
  # Instructions
72
  st.caption('Click on the table and press ctrl+f (or command+f for mac) to search it')
73
 
74
+ # Make the link clickable
75
+ def make_clickable(val):
76
+ return f'<a target="_blank" href="{val}">{val}</a>'
77
+
78
+ dat.style.format({'href': make_clickable})
79
+
80
  # Place a table under the plot
81
  st.dataframe(dat)
flycheck_app.py DELETED
@@ -1,75 +0,0 @@
1
- import streamlit as st
2
- from duckduckgo_search import ddg
3
- import pandas as pd
4
- from sentence_transformers import SentenceTransformer
5
- import umap.umap_ as umap
6
- import numpy as np
7
- import sys
8
- import plotly.express as px
9
- import re
10
- import sklearn.cluster as cluster
11
-
12
- # The search bar
13
- keywords = st.text_input('Enter your search', 'How to use ChatGPT')
14
-
15
- # Set keywords as command line argument
16
- # print("searching for: " + ' '.join(sys.argv[1:]) + "...")
17
- # keywords = ' '.join(sys.argv[1:])
18
-
19
- to_display = 'body' # Sometimes this is title
20
- md = ddg(keywords, region='wt-wt', safesearch='Moderate', time='y', max_results=500)
21
- md = pd.DataFrame(md)
22
-
23
- # Load the model
24
- print("running sentence embeddings...")
25
- # model_name = 'all-mpnet-base-v2'
26
- model_name = 'all-MiniLM-L6-v2'
27
- model = SentenceTransformer(model_name)
28
- sentence_embeddings = model.encode(md['body'].tolist(), show_progress_bar = True)
29
- sentence_embeddings = pd.DataFrame(sentence_embeddings)
30
-
31
- # Reduce dimensionality
32
- print("reducing dimensionality...")
33
- reducer = umap.UMAP(metric = 'cosine')
34
- dimr = reducer.fit_transform(sentence_embeddings)
35
- dimr = pd.DataFrame(dimr, columns = ['umap1', 'umap2'])
36
-
37
- columns = ['title', 'href', 'body']
38
-
39
- # Clustering
40
- labels = cluster.KMeans(n_clusters=5).fit_predict(dimr[['umap1', 'umap2']])
41
- dimr['cluster'] = labels
42
-
43
- # Merge the data together
44
- dat = pd.concat([md.reset_index(), dimr.reset_index()], axis = 1)
45
-
46
- # handle duplicate index columns
47
- dat = dat.loc[:,~dat.columns.duplicated()]
48
-
49
- # Get it ready for plotting
50
- dat['title'] = dat.title.str.wrap(30).apply(lambda x: x.replace('\n', '<br>'))
51
- dat['body'] = dat.body.str.wrap(30).apply(lambda x: x.replace('\n', '<br>'))
52
-
53
- # Visualize
54
- fig = px.scatter(dat, x = 'umap1', y = 'umap2', hover_data = ['title', 'body'], color = 'cluster', title = 'Context similarity map of results')
55
-
56
- # Make the font a little bigger
57
- fig.update_layout(
58
- hoverlabel=dict(
59
- bgcolor="white",
60
- font_size=16
61
- )
62
- )
63
-
64
- # Show the figure
65
- st.plotly_chart(fig, use_container_width=True)
66
-
67
- # Remove <br> in the text for the table
68
- dat['title'] = [re.sub('<br>', ' ', i) for i in dat['title']]
69
- dat['body'] = [re.sub('<br>', ' ', i) for i in dat['body']]
70
-
71
- # Instructions
72
- st.caption('Click on the table and press ctrl+f (or command+f for mac) to search it')
73
-
74
- # Place a table under the plot
75
- st.dataframe(dat)