Stepheni12 commited on
Commit
f13d295
·
1 Parent(s): 3379d6f

Update output formatting to html

Browse files
Files changed (1) hide show
  1. app.py +107 -18
app.py CHANGED
@@ -2,43 +2,132 @@ import chromadb
2
  import os
3
  import gradio as gr
4
 
5
- client = chromadb.PersistentClient(path="./db1")
6
  collection = client.get_or_create_collection("test")
7
 
8
  def query_episodes(query, n_results):
9
- output = ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  q = collection.query(
12
  query_texts=[query],
13
  n_results=n_results)
14
 
 
 
15
  for idx in range(n_results):
16
- output += "Episode Title: {}\nParagraph: {}\nExcerpt: {}".format(q["metadatas"][0][idx]["title"], q["metadatas"][0][idx]["paragraph"], q["documents"][0][idx])
17
- if idx+1 < n_results:
18
- output += "\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  return output
21
 
22
 
23
  if __name__ == "__main__":
24
- description = "With a podcast like the Huberman Lab podcast it can sometimes be overwhelming trying to find the exact content you are looking for. This tool is meant to start you in the right direction depending on the topic you are searching for."
25
- article = """For any input or suggestions hit me up on [twitter](https://twitter.com/intent/user?screen_name=_isteph_)!"""
26
- examples = [
27
  ["Stretching routine", 3],
28
  ["Cold exposure", 5],
29
  ["Handling ADHD", 2],
30
  ["Eating healthy", 8]
31
  ]
32
 
33
- interface = gr.Interface(
34
- fn=query_episodes,
35
- inputs=[gr.Textbox(label="Search Query",show_label=True), gr.Slider(value=3, minimum=1, maximum=10, step=1, label="Number of Results")],
36
- outputs=[gr.Textbox(label="Consolidated Query Results", show_label=True)],
37
- title="Huberman Lab Podcast Topic Search",
38
- examples=examples,
39
- description=description,
40
- article=article
41
- )
42
 
43
 
44
- interface.launch()
 
2
  import os
3
  import gradio as gr
4
 
5
+ client = chromadb.PersistentClient(path="./db")
6
  collection = client.get_or_create_collection("test")
7
 
8
  def query_episodes(query, n_results):
9
+ output = """
10
+ <!DOCTYPE html>
11
+ <html lang="en">
12
+ <head>
13
+ <meta charset="UTF-8">
14
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
15
+ <title>Podcast Episodes</title>
16
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">
17
+ <style>
18
+ body {
19
+ font-family: 'Roboto', sans-serif;
20
+ background-color: #000000;
21
+ margin: 0;
22
+ padding: 20px; /* Add padding to the body to separate it from the podcast container */
23
+ box-sizing: border-box;
24
+ }
25
+
26
+ .podcast-container {
27
+ max-height: 500px; /* Set a fixed height for the podcast container */
28
+ overflow-y: auto; /* Enable scrolling if content exceeds the container height */
29
+ width: 600px; /* Set a fixed width for the podcast container */
30
+ margin: auto; /* Center the podcast container horizontally */
31
+ }
32
+
33
+ .episode-container {
34
+ background-color: #1c1c1c;
35
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
36
+ border-radius: 8px;
37
+ overflow: hidden;
38
+ margin-bottom: 20px;
39
+ color: #ffffff;
40
+ }
41
+
42
+ .episode-title {
43
+ background-color: #3498db;
44
+ color: #ffffff;
45
+ padding: 15px;
46
+ font-size: 22px;
47
+ font-weight: bold;
48
+ text-align: center;
49
+ }
50
+
51
+ .episode-content {
52
+ display: flex;
53
+ flex-direction: column;
54
+ align-items: center;
55
+ justify-content: center;
56
+ padding: 20px;
57
+ overflow-y: auto;
58
+ }
59
+
60
+ .paragraph-number {
61
+ font-size: 18px;
62
+ color: #3498db;
63
+ margin-bottom: 8px;
64
+ }
65
+
66
+ .paragraph-text {
67
+ font-size: 16px;
68
+ color: #cccccc;
69
+ line-height: 1.4;
70
+ text-align: center;
71
+ }
72
+
73
+ /* Hide the scrollbar */
74
+ .podcast-container::-webkit-scrollbar {
75
+ width: 0 !important;
76
+ display: none;
77
+ }
78
+ </style>
79
+ </head>
80
+ <body>
81
+ <div class="podcast-container">
82
+ """
83
 
84
  q = collection.query(
85
  query_texts=[query],
86
  n_results=n_results)
87
 
88
+ print(q)
89
+
90
  for idx in range(n_results):
91
+ output += """
92
+ <div class="episode-container">
93
+ <div class="episode-title">Episode Title: {}</div>
94
+ <div class="episode-content">
95
+ <div class="paragraph-number">Paragraph: {}</div>
96
+ <div class="paragraph-text">
97
+ {}
98
+ </div>
99
+ </div>
100
+ </div>
101
+ """.format(q["metadatas"][0][idx]["title"], q["metadatas"][0][idx]["paragraph"], q["documents"][0][idx])
102
+
103
+ output += """
104
+ </div>
105
+ </body>
106
+ </html>
107
+ """
108
 
109
  return output
110
 
111
 
112
  if __name__ == "__main__":
113
+ description = "With a podcast like the Huberman Lab podcast it can sometimes be overwhelming trying to find the exact content you are looking for. This tool is meant to start you in the right direction depending on the topic you are searching for."
114
+ article = """For any input or suggestions hit me up on [twitter](https://twitter.com/intent/user?screen_name=_isteph_)!"""
115
+ examples = [
116
  ["Stretching routine", 3],
117
  ["Cold exposure", 5],
118
  ["Handling ADHD", 2],
119
  ["Eating healthy", 8]
120
  ]
121
 
122
+ interface = gr.Interface(
123
+ fn=query_episodes,
124
+ inputs=[gr.Textbox(label="Search Query",show_label=True), gr.Slider(value=3, minimum=1, maximum=10, step=1, label="Number of Results")],
125
+ outputs=[gr.HTML(label="Consolidated Query Results", show_label=True)],
126
+ title="Huberman Lab Podcast Topic Search",
127
+ examples=examples,
128
+ description=description,
129
+ article=article
130
+ )
131
 
132
 
133
+ interface.launch()