Added single dummy modal call at startup to warm container.
Browse files- functions/gradio_functions.py +49 -0
- rss_server.py +6 -2
functions/gradio_functions.py
CHANGED
@@ -2,6 +2,55 @@
|
|
2 |
|
3 |
import os
|
4 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
def update_log(n: int = 10):
|
|
|
2 |
|
3 |
import os
|
4 |
import re
|
5 |
+
import logging
|
6 |
+
|
7 |
+
from openai import OpenAI
|
8 |
+
|
9 |
+
async def call_modal() -> None:
|
10 |
+
'''Sends request to Modal to spin up container'''
|
11 |
+
|
12 |
+
logger = logging.getLogger(__name__ + '.call_modal()')
|
13 |
+
|
14 |
+
# Call the modal container so it spins up
|
15 |
+
client = OpenAI(api_key=os.environ['MODAL_API_KEY'])
|
16 |
+
|
17 |
+
client.base_url = (
|
18 |
+
'https://gperdrizet--vllm-openai-compatible-summarization-serve.modal.run/v1'
|
19 |
+
)
|
20 |
+
|
21 |
+
# Default to first avalible model
|
22 |
+
model = client.models.list().data[0]
|
23 |
+
model_id = model.id
|
24 |
+
|
25 |
+
messages = [
|
26 |
+
{
|
27 |
+
'role': 'system',
|
28 |
+
'content': ('Interpret the following proverb in 50 words or less: ' +
|
29 |
+
'A poor craftsman blames the eye of the beholder')
|
30 |
+
}
|
31 |
+
]
|
32 |
+
|
33 |
+
logger.info('Prompt: %s': messages[0]['content'])
|
34 |
+
|
35 |
+
completion_args = {
|
36 |
+
'model': model_id,
|
37 |
+
'messages': messages,
|
38 |
+
}
|
39 |
+
|
40 |
+
try:
|
41 |
+
response = client.chat.completions.create(**completion_args)
|
42 |
+
|
43 |
+
except Exception as e: # pylint: disable=broad-exception-caught
|
44 |
+
response = None
|
45 |
+
logger.error('Error during Modal API call: %s', e)
|
46 |
+
|
47 |
+
if response is not None:
|
48 |
+
reply = response.choices[0].message.content
|
49 |
+
|
50 |
+
else:
|
51 |
+
reply = None
|
52 |
+
|
53 |
+
logger.info('Reply: %s', reply)
|
54 |
|
55 |
|
56 |
def update_log(n: int = 10):
|
rss_server.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
'''Main script to run gradio interface and MCP server.'''
|
2 |
|
|
|
3 |
import logging
|
4 |
-
from functools import partial
|
5 |
from pathlib import Path
|
6 |
from logging.handlers import RotatingFileHandler
|
7 |
|
@@ -10,6 +10,8 @@ import assets.html as html
|
|
10 |
import functions.tools as tool_funcs
|
11 |
import functions.gradio_functions as gradio_funcs
|
12 |
|
|
|
|
|
13 |
|
14 |
# Set-up logging
|
15 |
# Make sure log directory exists
|
@@ -40,7 +42,9 @@ with gr.Blocks() as demo:
|
|
40 |
gr.HTML(html.DESCRIPTION)
|
41 |
|
42 |
# Log output
|
43 |
-
|
|
|
|
|
44 |
timer = gr.Timer(0.5, active=True)
|
45 |
|
46 |
timer.tick( # pylint: disable=no-member
|
|
|
1 |
'''Main script to run gradio interface and MCP server.'''
|
2 |
|
3 |
+
import asyncio
|
4 |
import logging
|
|
|
5 |
from pathlib import Path
|
6 |
from logging.handlers import RotatingFileHandler
|
7 |
|
|
|
10 |
import functions.tools as tool_funcs
|
11 |
import functions.gradio_functions as gradio_funcs
|
12 |
|
13 |
+
# Call the modal container so it spins up
|
14 |
+
asyncio.run(gradio_funcs.call_modal())
|
15 |
|
16 |
# Set-up logging
|
17 |
# Make sure log directory exists
|
|
|
42 |
gr.HTML(html.DESCRIPTION)
|
43 |
|
44 |
# Log output
|
45 |
+
with gr.Row():
|
46 |
+
dialog_output = gr.Textbox(label='Server logs', lines=5, max_lines=5)
|
47 |
+
|
48 |
timer = gr.Timer(0.5, active=True)
|
49 |
|
50 |
timer.tick( # pylint: disable=no-member
|