zamalali commited on
Commit
2da0a7b
·
1 Parent(s): 777083e

Enhance DeepGit Lite UI and functionality by integrating GPU support for repository ranking, refining HTML structure, and improving user feedback mechanisms.

Browse files
Files changed (1) hide show
  1. app.py +27 -57
app.py CHANGED
@@ -2,7 +2,8 @@ import gradio as gr
2
  import time
3
  import threading
4
  import logging
5
- from main import run_repository_ranking # Import the new function from main.py
 
6
 
7
  # ---------------------------
8
  # Global Logging Buffer Setup
@@ -37,7 +38,7 @@ def filter_logs(logs):
37
  return filtered
38
 
39
  # ---------------------------
40
- # Title, Favicon & Description
41
  # ---------------------------
42
  favicon_html = """
43
  <head>
@@ -47,23 +48,20 @@ favicon_html = """
47
  """
48
 
49
  title = """
50
- <div style="text-align: center; margin-top: 20px;">
51
- <h1 style="font-size: 36px; display: inline-flex; align-items: center; gap: 16px;">
52
- <img src="https://img.icons8.com/?size=100&id=118557&format=png&color=000000" width="64" />
53
- <span>DeepGit Lite</span>
54
- </h1>
55
- <p style="font-size: 18px; color: #555; margin-top: 10px;">
56
- ⚙️ A lightweight GitHub research agent for deep semantic search and ranking.
57
- </p>
58
  </div>
59
  """
60
 
61
- description = """<p align="center">
 
62
  DeepGit Lite is a streamlined tool for semantic search on GitHub repositories. It retrieves repositories using dense retrieval, ranks them by similarity, and then presents the top results.
63
- </p>"""
 
64
 
65
  consent_text = """
66
- <div style="padding: 10px; text-align: center;">
67
  <p>
68
  By using DeepGit Lite, you consent to temporary processing of your query for semantic search and ranking purposes.
69
  </p>
@@ -75,42 +73,15 @@ consent_text = """
75
  """
76
 
77
  footer = """
78
- <div style="text-align: center; margin-top: 40px; font-size: 13px; color: #888;">
79
- Made with <span style="color: crimson;">❤️</span> by <b>Zamal</b>
80
  </div>
81
  """
82
 
83
- # ---------------------------
84
- # HTML Table Renderer for Results
85
- # ---------------------------
86
- def format_percent(value):
87
- try:
88
- return f"{float(value) * 100:.1f}%"
89
- except:
90
- return value
91
-
92
  def parse_result_to_html(raw_result: str) -> str:
93
  entries = raw_result.strip().split("Final Rank:")
94
  html = """
95
- <style>
96
- table {
97
- width: 100%;
98
- border-collapse: collapse;
99
- margin: 1em 0;
100
- font-size: 14px;
101
- }
102
- th, td {
103
- padding: 12px 15px;
104
- border: 1px solid #ddd;
105
- text-align: left;
106
- vertical-align: top;
107
- }
108
- th {
109
- background-color: #f4f4f4;
110
- }
111
- tr:hover { background-color: #f9f9f9; }
112
- </style>
113
- <table>
114
  <thead>
115
  <tr>
116
  <th>Rank</th>
@@ -141,10 +112,14 @@ def parse_result_to_html(raw_result: str) -> str:
141
  return html
142
 
143
  # ---------------------------
144
- # Background Workflow Runner
145
  # ---------------------------
 
 
 
 
146
  def run_lite_workflow(topic, result_container):
147
- result = run_repository_ranking(topic)
148
  result_container["raw_result"] = result
149
 
150
  def stream_lite_workflow(topic):
@@ -169,30 +144,23 @@ def stream_lite_workflow(topic):
169
  workflow_thread.join()
170
  with LOG_BUFFER_LOCK:
171
  final_logs = LOG_BUFFER[:]
172
- filtered_final = filter_logs(final_logs)
173
  raw_result = result_container.get("raw_result", "No results returned.")
174
  html_result = parse_result_to_html(raw_result)
175
  yield "", html_result
176
 
177
  # ---------------------------
178
- # App UI Setup for DeepGit Lite
179
  # ---------------------------
180
- with gr.Blocks(
181
- css="""
182
- #main_container { margin: auto; max-width: 900px; }
183
- footer, footer * { display: none !important; }
184
- """
185
- ) as demo:
186
-
187
  gr.HTML(favicon_html)
188
  gr.HTML(title)
189
  gr.HTML(description)
190
 
191
- with gr.Column(elem_id="user_consent_container") as consent_block:
192
  gr.HTML(consent_text)
193
  agree_button = gr.Button("I Agree", variant="primary")
194
 
195
- with gr.Column(elem_id="main_container", visible=False) as main_block:
196
  research_input = gr.Textbox(
197
  label="Research Topic",
198
  placeholder="Enter your research topic here, e.g., 'Fine tuning Instruction tuned LLama models...'",
@@ -209,7 +177,7 @@ with gr.Blocks(
209
 
210
  agree_button.click(fn=enable_main, inputs=[], outputs=[consent_block, main_block], queue=False)
211
 
212
- # Added initial yield for immediate feedback when the button is pressed.
213
  def lite_runner(topic):
214
  yield "Workflow started", "<p>Processing your request. Please wait...</p>"
215
  for status, details in stream_lite_workflow(topic):
@@ -232,4 +200,6 @@ with gr.Blocks(
232
  )
233
 
234
  gr.HTML(footer)
 
235
  demo.queue(max_size=10).launch()
 
 
2
  import time
3
  import threading
4
  import logging
5
+ import spaces
6
+ from main import run_repository_ranking # Import the repository ranking function
7
 
8
  # ---------------------------
9
  # Global Logging Buffer Setup
 
38
  return filtered
39
 
40
  # ---------------------------
41
+ # Minimal Title, Favicon & Description
42
  # ---------------------------
43
  favicon_html = """
44
  <head>
 
48
  """
49
 
50
  title = """
51
+ <div>
52
+ <h1>DeepGit Lite</h1>
53
+ <p>⚙️ A lightweight GitHub research agent for deep semantic search and ranking.</p>
 
 
 
 
 
54
  </div>
55
  """
56
 
57
+ description = """
58
+ <p>
59
  DeepGit Lite is a streamlined tool for semantic search on GitHub repositories. It retrieves repositories using dense retrieval, ranks them by similarity, and then presents the top results.
60
+ </p>
61
+ """
62
 
63
  consent_text = """
64
+ <div>
65
  <p>
66
  By using DeepGit Lite, you consent to temporary processing of your query for semantic search and ranking purposes.
67
  </p>
 
73
  """
74
 
75
  footer = """
76
+ <div>
77
+ Made with ❤️ by <b>Zamal</b>
78
  </div>
79
  """
80
 
 
 
 
 
 
 
 
 
 
81
  def parse_result_to_html(raw_result: str) -> str:
82
  entries = raw_result.strip().split("Final Rank:")
83
  html = """
84
+ <table border="1" style="width:100%; border-collapse: collapse;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  <thead>
86
  <tr>
87
  <th>Rank</th>
 
112
  return html
113
 
114
  # ---------------------------
115
+ # GPU-enabled Wrapper for Repository Ranking
116
  # ---------------------------
117
+ @spaces.GPU(duration=180)
118
+ def gpu_run_repo(topic: str):
119
+ return run_repository_ranking(topic)
120
+
121
  def run_lite_workflow(topic, result_container):
122
+ result = gpu_run_repo(topic)
123
  result_container["raw_result"] = result
124
 
125
  def stream_lite_workflow(topic):
 
144
  workflow_thread.join()
145
  with LOG_BUFFER_LOCK:
146
  final_logs = LOG_BUFFER[:]
 
147
  raw_result = result_container.get("raw_result", "No results returned.")
148
  html_result = parse_result_to_html(raw_result)
149
  yield "", html_result
150
 
151
  # ---------------------------
152
+ # App UI Setup Using Default Gradio Theme
153
  # ---------------------------
154
+ with gr.Blocks() as demo:
 
 
 
 
 
 
155
  gr.HTML(favicon_html)
156
  gr.HTML(title)
157
  gr.HTML(description)
158
 
159
+ with gr.Column() as consent_block:
160
  gr.HTML(consent_text)
161
  agree_button = gr.Button("I Agree", variant="primary")
162
 
163
+ with gr.Column(visible=False) as main_block:
164
  research_input = gr.Textbox(
165
  label="Research Topic",
166
  placeholder="Enter your research topic here, e.g., 'Fine tuning Instruction tuned LLama models...'",
 
177
 
178
  agree_button.click(fn=enable_main, inputs=[], outputs=[consent_block, main_block], queue=False)
179
 
180
+ # Yield an initial status message for immediate feedback
181
  def lite_runner(topic):
182
  yield "Workflow started", "<p>Processing your request. Please wait...</p>"
183
  for status, details in stream_lite_workflow(topic):
 
200
  )
201
 
202
  gr.HTML(footer)
203
+
204
  demo.queue(max_size=10).launch()
205
+