Spaces:
Runtime error
Runtime error
File size: 5,039 Bytes
4dd70a8 f8a041b 4dd70a8 e249170 9e8809b 4dd70a8 fb7ecc7 9e8809b 9124a5f f8a041b 9e8809b f8a041b 6c67813 f8a041b 00764df f8a041b 6c67813 f8a041b e5249be 4dd70a8 9e8809b e249170 9e8809b facf739 9e8809b a3e696b e249170 a3e696b 9e8809b 5dd5c65 9e8809b 4dd70a8 facf739 9e8809b e249170 af9e498 e249170 8863982 e249170 687d26a 8863982 cade3d1 f8a041b 4dd70a8 facf739 cade3d1 e249170 2e66273 af9e498 2e66273 e249170 2e66273 cade3d1 2e66273 cade3d1 2e66273 cade3d1 facf739 2e66273 af9e498 2e66273 facf739 2e66273 facf739 af9e498 facf739 af9e498 e66e891 facf739 e66e891 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
'''Main script to run gradio interface and MCP server.'''
import logging
from pathlib import Path
from logging.handlers import RotatingFileHandler
import gradio as gr
import assets.text as text
import functions.tools as tool_funcs
import functions.gradio_functions as gradio_funcs
# Call the modal container so it spins up before the rest of
# the app starts
gradio_funcs.call_modal()
# Set-up logging - make sure log directory exists
Path('logs').mkdir(parents=True, exist_ok=True)
# Clear old logs if present
gradio_funcs.delete_old_logs('logs', 'rss_server')
# Set up the root logger so we catch logs from everything
logging.basicConfig(
handlers=[RotatingFileHandler(
'logs/rss_server.log',
maxBytes=100000,
backupCount=10,
mode='w'
)],
level=logging.INFO,
format='%(levelname)s - %(name)s - %(message)s'
)
# Get a logger
logger = logging.getLogger(__name__)
with gr.Blocks(title='RASS server') as demo:
# Page text
gr.HTML(text.TITLE)
gr.Markdown(text.DESCRIPTION)
# Log output
with gr.Row():
dialog_output = gr.Textbox(label='Server logs', lines=7, max_lines=5)
timer = gr.Timer(0.5, active=True)
timer.tick( # pylint: disable=no-member
lambda: gradio_funcs.update_log(), # pylint: disable=unnecessary-lambda
outputs=dialog_output,
show_api=False
)
# Get feed tool
gr.Markdown('### 1. `get_feed()`')
website_url = gr.Textbox('slashdot', label='Website')
feed_output = gr.Textbox(label='RSS entries', lines=7, max_lines=7)
with gr.Row():
website_submit_button = gr.Button('Submit website')
website_clear_button = gr.ClearButton(components=[website_url, feed_output])
website_submit_button.click( # pylint: disable=no-member
fn=tool_funcs.get_feed,
inputs=website_url,
outputs=feed_output,
api_name='Get RSS feed content'
)
# Vector search tool
gr.Markdown('### 2. `context_search()`')
context_search_query = gr.Textbox(
'How is the air traffic control system being updated?',
label='Context search query'
)
context_search_output = gr.Textbox(
label='Context search results',
lines=7,
max_lines=7
)
with gr.Row():
context_search_submit_button = gr.Button('Submit query')
context_search_clear_button = gr.ClearButton(
components=[context_search_query, context_search_output]
)
context_search_submit_button.click( # pylint: disable=no-member
fn=tool_funcs.context_search,
inputs=context_search_query,
outputs=context_search_output,
api_name='Context vector search'
)
# Find article tool
gr.Markdown('### 3. `find_article()`')
article_search_query = gr.Textbox(
'How is the air traffic control system being updated?',
label='Article search query'
)
article_search_output = gr.Textbox(
label='Article search results',
lines=3,
max_lines=3
)
with gr.Row():
article_search_submit_button = gr.Button('Submit query')
article_search_clear_button = gr.ClearButton(
components=[article_search_query, article_search_output]
)
article_search_submit_button.click( # pylint: disable=no-member
fn=tool_funcs.find_article,
inputs=article_search_query,
outputs=article_search_output,
api_name='Article vector search'
)
# Get summary tool
gr.Markdown('### 4. `get_summary()`')
article_title = gr.Textbox(
'FAA To Eliminate Floppy Disks Used In Air Traffic Control Systems',
label='Article title'
)
article_summary = gr.Textbox(
label='Article summary',
lines=3,
max_lines=3
)
with gr.Row():
article_title_submit_button = gr.Button('Submit title')
article_title_clear_button = gr.ClearButton(
components=[article_title, article_summary]
)
article_title_submit_button.click( # pylint: disable=no-member
fn=tool_funcs.get_summary,
inputs=article_title,
outputs=article_summary,
api_name='Article summary search'
)
# Get link tool
gr.Markdown('### 5. `get_link()`')
article_title_link = gr.Textbox(
'FAA To Eliminate Floppy Disks Used In Air Traffic Control Systems',
label='Article title'
)
article_link = gr.Textbox(
label='Article link',
lines=3,
max_lines=3
)
with gr.Row():
article_link_submit_button = gr.Button('Submit title')
article_link_clear_button = gr.ClearButton(
components=[article_title_link, article_link]
)
article_link_submit_button.click( # pylint: disable=no-member
fn=tool_funcs.get_link,
inputs=article_title_link,
outputs=article_link,
api_name='Article link search'
)
if __name__ == '__main__':
demo.launch(mcp_server=True)
|