PierreBrunelle
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,17 +3,16 @@ import pixeltable as pxt
|
|
3 |
from pixeltable.functions.mistralai import chat_completions
|
4 |
from datetime import datetime
|
5 |
from textblob import TextBlob
|
6 |
-
import re
|
7 |
import nltk
|
8 |
from nltk.tokenize import word_tokenize
|
9 |
from nltk.corpus import stopwords
|
10 |
import os
|
11 |
import getpass
|
|
|
12 |
|
13 |
# Ensure necessary NLTK data is downloaded
|
14 |
nltk.download('punkt', quiet=True)
|
15 |
nltk.download('stopwords', quiet=True)
|
16 |
-
nltk.download('punkt_tab', quiet=True)
|
17 |
|
18 |
# Set up Mistral API key
|
19 |
if 'MISTRAL_API_KEY' not in os.environ:
|
@@ -38,24 +37,24 @@ def calculate_readability(text: str) -> float:
|
|
38 |
average_words_per_sentence = words / sentences
|
39 |
return 206.835 - 1.015 * average_words_per_sentence
|
40 |
|
41 |
-
|
42 |
-
def run_inference_and_analysis(task, system_prompt, input_text, temperature, top_p, max_tokens, stop, random_seed, safe_prompt):
|
43 |
# Initialize Pixeltable
|
44 |
pxt.drop_table('mistral_prompts', ignore_errors=True)
|
45 |
t = pxt.create_table('mistral_prompts', {
|
46 |
-
'task': pxt.
|
47 |
-
'system': pxt.
|
48 |
-
'input_text': pxt.
|
49 |
-
'timestamp': pxt.
|
50 |
-
'temperature': pxt.
|
51 |
-
'top_p': pxt.
|
52 |
-
'max_tokens': pxt.
|
53 |
-
'
|
54 |
-
'
|
55 |
-
'
|
|
|
56 |
})
|
57 |
|
58 |
-
# Insert new row
|
59 |
t.insert([{
|
60 |
'task': task,
|
61 |
'system': system_prompt,
|
@@ -64,6 +63,7 @@ def run_inference_and_analysis(task, system_prompt, input_text, temperature, top
|
|
64 |
'temperature': temperature,
|
65 |
'top_p': top_p,
|
66 |
'max_tokens': max_tokens,
|
|
|
67 |
'stop': stop,
|
68 |
'random_seed': random_seed,
|
69 |
'safe_prompt': safe_prompt
|
@@ -80,56 +80,36 @@ def run_inference_and_analysis(task, system_prompt, input_text, temperature, top
|
|
80 |
'temperature': temperature,
|
81 |
'top_p': top_p,
|
82 |
'max_tokens': max_tokens if max_tokens is not None else 300,
|
|
|
83 |
'stop': stop.split(',') if stop else None,
|
84 |
'random_seed': random_seed,
|
85 |
'safe_prompt': safe_prompt
|
86 |
}
|
87 |
|
88 |
-
#
|
89 |
-
t
|
90 |
-
t
|
91 |
|
92 |
# Extract responses
|
93 |
-
t
|
94 |
-
t
|
95 |
|
96 |
-
#
|
97 |
-
t
|
98 |
-
t
|
99 |
-
t
|
100 |
-
t
|
101 |
-
t
|
102 |
-
t
|
103 |
|
104 |
-
#
|
105 |
results = t.select(
|
106 |
t.omn_response, t.ml_response,
|
107 |
t.large_sentiment_score, t.open_sentiment_score,
|
108 |
t.large_keywords, t.open_keywords,
|
109 |
t.large_readability_score, t.open_readability_score
|
110 |
).tail(1)
|
111 |
-
|
112 |
-
history = t.select(t.timestamp, t.task, t.system, t.input_text).order_by(t.timestamp, asc=False).collect().to_pandas()
|
113 |
-
responses = t.select(t.timestamp, t.omn_response, t.ml_response).order_by(t.timestamp, asc=False).collect().to_pandas()
|
114 |
-
analysis = t.select(
|
115 |
-
t.timestamp,
|
116 |
-
t.open_sentiment_score,
|
117 |
-
t.large_sentiment_score,
|
118 |
-
t.open_keywords,
|
119 |
-
t.large_keywords,
|
120 |
-
t.open_readability_score,
|
121 |
-
t.large_readability_score
|
122 |
-
).order_by(t.timestamp, asc=False).collect().to_pandas()
|
123 |
-
params = t.select(
|
124 |
-
t.timestamp,
|
125 |
-
t.temperature,
|
126 |
-
t.top_p,
|
127 |
-
t.max_tokens,
|
128 |
-
t.stop,
|
129 |
-
t.random_seed,
|
130 |
-
t.safe_prompt
|
131 |
-
).order_by(t.timestamp, asc=False).collect().to_pandas()
|
132 |
-
|
133 |
return (
|
134 |
results['omn_response'][0],
|
135 |
results['ml_response'][0],
|
@@ -138,309 +118,91 @@ def run_inference_and_analysis(task, system_prompt, input_text, temperature, top
|
|
138 |
results['large_keywords'][0],
|
139 |
results['open_keywords'][0],
|
140 |
results['large_readability_score'][0],
|
141 |
-
results['open_readability_score'][0]
|
142 |
-
history,
|
143 |
-
responses,
|
144 |
-
analysis,
|
145 |
-
params
|
146 |
)
|
147 |
|
148 |
def gradio_interface():
|
149 |
-
with gr.Blocks(
|
150 |
-
#
|
151 |
-
gr.HTML("""
|
152 |
-
<div style="text-align: center; padding: 20px; background: linear-gradient(to right, #4F46E5, #7C3AED);" class="shadow-lg">
|
153 |
-
<img src="https://raw.githubusercontent.com/pixeltable/pixeltable/main/docs/source/data/pixeltable-logo-large.png"
|
154 |
-
alt="Pixeltable" style="max-width: 200px; margin-bottom: 15px;" />
|
155 |
-
<h1 style="color: white; font-size: 2.5rem; margin-bottom: 10px;">LLM Studio</h1>
|
156 |
-
<p style="color: #E5E7EB; font-size: 1.1rem;">
|
157 |
-
Powered by Pixeltable's Unified AI Data Infrastructure
|
158 |
-
</p>
|
159 |
-
</div>
|
160 |
-
""")
|
161 |
|
162 |
-
# Product Overview Cards
|
163 |
with gr.Row():
|
164 |
with gr.Column():
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
with gr.Column():
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
<li style="margin-bottom: 8px;">🔄 Compare multiple LLM models side-by-side</li>
|
183 |
-
<li style="margin-bottom: 8px;">📈 Track and analyze model performance</li>
|
184 |
-
<li style="margin-bottom: 8px;">🎯 Experiment with different prompts and parameters</li>
|
185 |
-
<li style="margin-bottom: 8px;">📝 Automatic analysis with sentiment and readability scores</li>
|
186 |
-
</ul>
|
187 |
-
</div>
|
188 |
-
""")
|
189 |
-
|
190 |
-
# Main Interface
|
191 |
-
with gr.Tabs() as tabs:
|
192 |
-
with gr.TabItem("🎯 Experiment", id=0):
|
193 |
with gr.Row():
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
label="Open-Mistral-Nemo Response",
|
205 |
-
elem_classes="output-style"
|
206 |
-
)
|
207 |
-
ml_response = gr.Textbox(
|
208 |
-
label="Mistral-Medium Response",
|
209 |
-
elem_classes="output-style"
|
210 |
-
)
|
211 |
-
large_sentiment = gr.Number(label="Mistral-Medium Sentiment")
|
212 |
-
open_sentiment = gr.Number(label="Open-Mistral-Nemo Sentiment")
|
213 |
-
large_keywords = gr.Textbox(label="Mistral-Medium Keywords")
|
214 |
-
open_keywords = gr.Textbox(label="Open-Mistral-Nemo Keywords")
|
215 |
-
large_readability = gr.Number(label="Mistral-Medium Readability")
|
216 |
-
open_readability = gr.Number(label="Open-Mistral-Nemo Readability")
|
217 |
-
|
218 |
-
# Now define input components
|
219 |
-
task = gr.Textbox(
|
220 |
-
label="Task Category",
|
221 |
-
placeholder="e.g., Sentiment Analysis, Text Generation, Summarization",
|
222 |
-
elem_classes="input-style"
|
223 |
-
)
|
224 |
-
system_prompt = gr.Textbox(
|
225 |
-
label="System Prompt",
|
226 |
-
placeholder="Define the AI's role and task...",
|
227 |
-
lines=3,
|
228 |
-
elem_classes="input-style"
|
229 |
-
)
|
230 |
-
input_text = gr.Textbox(
|
231 |
-
label="Input Text",
|
232 |
-
placeholder="Enter your prompt or text to analyze...",
|
233 |
-
lines=4,
|
234 |
-
elem_classes="input-style"
|
235 |
-
)
|
236 |
-
|
237 |
-
with gr.Accordion("🛠️ Advanced Settings", open=False):
|
238 |
-
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, step=0.1, label="Temperature")
|
239 |
-
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, step=0.1, label="Top P")
|
240 |
-
max_tokens = gr.Number(label="Max Tokens", value=300)
|
241 |
-
min_tokens = gr.Number(label="Min Tokens", value=None)
|
242 |
-
stop = gr.Textbox(label="Stop Sequences (comma-separated)")
|
243 |
-
random_seed = gr.Number(label="Random Seed", value=None)
|
244 |
-
safe_prompt = gr.Checkbox(label="Safe Prompt", value=False)
|
245 |
-
|
246 |
-
# Add Examples Section with enhanced styling
|
247 |
-
gr.HTML("""
|
248 |
-
<div style="padding: 15px; background-color: #F3F4F6; border-radius: 8px; margin: 20px 0;">
|
249 |
-
<h3 style="color: #4F46E5; margin-bottom: 10px;">📚 Example Prompts</h3>
|
250 |
-
<p style="color: #6B7280; font-size: 0.9rem;">Try these pre-configured examples to get started</p>
|
251 |
-
</div>
|
252 |
-
""")
|
253 |
-
|
254 |
-
examples = [
|
255 |
-
# Example 1: Sentiment Analysis
|
256 |
-
["Sentiment Analysis",
|
257 |
-
"You are an AI trained to analyze the sentiment of text. Provide a detailed analysis of the emotional tone, highlighting key phrases that indicate sentiment.",
|
258 |
-
"The new restaurant downtown exceeded all my expectations. The food was exquisite, the service impeccable, and the ambiance was perfect for a romantic evening. I can't wait to go back!",
|
259 |
-
0.3, 0.95, 200, None, "", None, False],
|
260 |
-
|
261 |
-
# Example 2: Creative Writing
|
262 |
-
["Story Generation",
|
263 |
-
"You are a creative writer. Generate a short, engaging story based on the given prompt. Include vivid descriptions and an unexpected twist.",
|
264 |
-
"In a world where dreams are shared, a young girl discovers she can manipulate other people's dreams.",
|
265 |
-
0.9, 0.8, 500, 300, "The end", None, False]
|
266 |
-
]
|
267 |
-
|
268 |
-
with gr.Group(elem_classes="examples-container"):
|
269 |
-
gr.Examples(
|
270 |
-
examples=examples,
|
271 |
-
inputs=[
|
272 |
-
task, system_prompt, input_text,
|
273 |
-
temperature, top_p, max_tokens,
|
274 |
-
min_tokens, stop, random_seed,
|
275 |
-
safe_prompt
|
276 |
-
],
|
277 |
-
outputs=[
|
278 |
-
omn_response, ml_response,
|
279 |
-
large_sentiment, open_sentiment,
|
280 |
-
large_keywords, open_keywords,
|
281 |
-
large_readability, open_readability
|
282 |
-
],
|
283 |
-
fn=run_inference_and_analysis,
|
284 |
-
cache_examples=True
|
285 |
-
)
|
286 |
-
|
287 |
-
submit_btn = gr.Button(
|
288 |
-
"🚀 Run Analysis",
|
289 |
-
variant="primary",
|
290 |
-
scale=1,
|
291 |
-
min_width=200
|
292 |
-
)
|
293 |
-
|
294 |
-
with gr.Column(scale=1):
|
295 |
-
gr.HTML("""
|
296 |
-
<div style="padding: 15px; background-color: #F3F4F6; border-radius: 8px; margin-bottom: 15px;">
|
297 |
-
<h3 style="color: #4F46E5; margin-bottom: 10px;">Results</h3>
|
298 |
-
<p style="color: #6B7280; font-size: 0.9rem;">Compare model outputs and analysis metrics</p>
|
299 |
-
</div>
|
300 |
-
""")
|
301 |
-
|
302 |
-
with gr.Group():
|
303 |
-
omn_response = gr.Textbox(
|
304 |
-
label="Open-Mistral-Nemo Response",
|
305 |
-
elem_classes="output-style"
|
306 |
-
)
|
307 |
-
ml_response = gr.Textbox(
|
308 |
-
label="Mistral-Medium Response",
|
309 |
-
elem_classes="output-style"
|
310 |
-
)
|
311 |
-
|
312 |
-
with gr.Group():
|
313 |
-
with gr.Row():
|
314 |
-
with gr.Column():
|
315 |
-
gr.HTML("<h4>📊 Sentiment Analysis</h4>")
|
316 |
-
large_sentiment = gr.Number(label="Mistral-Medium")
|
317 |
-
open_sentiment = gr.Number(label="Open-Mistral-Nemo")
|
318 |
-
|
319 |
-
with gr.Column():
|
320 |
-
gr.HTML("<h4>📈 Readability Scores</h4>")
|
321 |
-
large_readability = gr.Number(label="Mistral-Medium")
|
322 |
-
open_readability = gr.Number(label="Open-Mistral-Nemo")
|
323 |
-
|
324 |
-
gr.HTML("<h4>🔑 Key Terms</h4>")
|
325 |
-
with gr.Row():
|
326 |
-
large_keywords = gr.Textbox(label="Mistral-Medium Keywords")
|
327 |
-
open_keywords = gr.Textbox(label="Open-Mistral-Nemo Keywords")
|
328 |
-
|
329 |
-
with gr.TabItem("📊 History & Analysis", id=1):
|
330 |
-
with gr.Tabs():
|
331 |
-
with gr.TabItem("Prompt History"):
|
332 |
-
history = gr.DataFrame(
|
333 |
-
headers=["Timestamp", "Task", "System Prompt", "Input Text"],
|
334 |
-
wrap=True,
|
335 |
-
elem_classes="table-style"
|
336 |
-
)
|
337 |
-
|
338 |
-
with gr.TabItem("Model Responses"):
|
339 |
-
responses = gr.DataFrame(
|
340 |
-
headers=["Timestamp", "Open-Mistral-Nemo", "Mistral-Medium"],
|
341 |
-
wrap=True,
|
342 |
-
elem_classes="table-style"
|
343 |
-
)
|
344 |
-
|
345 |
-
with gr.TabItem("Analysis Results"):
|
346 |
-
analysis = gr.DataFrame(
|
347 |
-
headers=[
|
348 |
-
"Timestamp",
|
349 |
-
"Open-Mistral-Nemo Sentiment",
|
350 |
-
"Mistral-Medium Sentiment",
|
351 |
-
"Open-Mistral-Nemo Keywords",
|
352 |
-
"Mistral-Medium Keywords",
|
353 |
-
"Open-Mistral-Nemo Readability",
|
354 |
-
"Mistral-Medium Readability"
|
355 |
-
],
|
356 |
-
wrap=True,
|
357 |
-
elem_classes="table-style"
|
358 |
-
)
|
359 |
-
|
360 |
-
with gr.TabItem("Model Parameters"):
|
361 |
-
params = gr.DataFrame(
|
362 |
-
headers=[
|
363 |
-
"Timestamp",
|
364 |
-
"Temperature",
|
365 |
-
"Top P",
|
366 |
-
"Max Tokens",
|
367 |
-
"Stop Sequences",
|
368 |
-
"Random Seed",
|
369 |
-
"Safe Prompt"
|
370 |
-
],
|
371 |
-
wrap=True,
|
372 |
-
elem_classes="table-style"
|
373 |
-
)
|
374 |
-
|
375 |
-
# Footer with links and additional info
|
376 |
-
gr.HTML("""
|
377 |
-
<div style="text-align: center; padding: 20px; margin-top: 30px; border-top: 1px solid #E5E7EB;">
|
378 |
-
<div style="margin-bottom: 20px;">
|
379 |
-
<h3 style="color: #4F46E5;">Built with Pixeltable</h3>
|
380 |
-
<p style="color: #6B7280;">The unified data infrastructure for AI applications</p>
|
381 |
-
</div>
|
382 |
-
<div style="display: flex; justify-content: center; gap: 20px;">
|
383 |
-
<a href="https://github.com/pixeltable/pixeltable" target="_blank"
|
384 |
-
style="color: #4F46E5; text-decoration: none;">
|
385 |
-
📚 Documentation
|
386 |
-
</a>
|
387 |
-
<a href="https://github.com/pixeltable/pixeltable" target="_blank"
|
388 |
-
style="color: #4F46E5; text-decoration: none;">
|
389 |
-
💻 GitHub
|
390 |
-
</a>
|
391 |
-
<a href="https://join.slack.com/t/pixeltablecommunity/shared_invite/zt-21fybjbn2-fZC_SJiuG6QL~Ai8T6VpFQ" target="_blank"
|
392 |
-
style="color: #4F46E5; text-decoration: none;">
|
393 |
-
💬 Community
|
394 |
-
</a>
|
395 |
-
</div>
|
396 |
-
</div>
|
397 |
-
""")
|
398 |
-
|
399 |
-
# Custom CSS
|
400 |
-
gr.HTML("""
|
401 |
-
<style>
|
402 |
-
.examples-container {
|
403 |
-
margin: 20px 0;
|
404 |
-
padding: 15px;
|
405 |
-
border: 1px solid #E5E7EB;
|
406 |
-
border-radius: 8px;
|
407 |
-
background-color: white;
|
408 |
-
}
|
409 |
-
.examples-container .gr-samples-table {
|
410 |
-
border-collapse: separate;
|
411 |
-
border-spacing: 0 8px;
|
412 |
-
}
|
413 |
-
.examples-container .gr-samples-table tr {
|
414 |
-
background-color: #F9FAFB;
|
415 |
-
border: 1px solid #E5E7EB;
|
416 |
-
border-radius: 6px;
|
417 |
-
transition: all 0.2s;
|
418 |
-
}
|
419 |
-
.examples-container .gr-samples-table tr:hover {
|
420 |
-
background-color: #F3F4F6;
|
421 |
-
border-color: #4F46E5;
|
422 |
-
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
423 |
-
}
|
424 |
-
.examples-container .gr-samples-table td {
|
425 |
-
padding: 12px;
|
426 |
-
border: none;
|
427 |
-
}
|
428 |
-
</style>
|
429 |
-
""")
|
430 |
|
431 |
submit_btn.click(
|
432 |
run_inference_and_analysis,
|
433 |
inputs=[
|
434 |
-
task, system_prompt, input_text,
|
435 |
-
temperature, top_p, max_tokens,
|
436 |
-
stop, random_seed,
|
|
|
437 |
],
|
438 |
outputs=[
|
439 |
-
omn_response, ml_response,
|
440 |
-
large_sentiment, open_sentiment,
|
441 |
-
large_keywords, open_keywords,
|
442 |
-
large_readability, open_readability
|
443 |
-
history, responses, analysis, params # Added params here
|
444 |
]
|
445 |
)
|
446 |
|
|
|
3 |
from pixeltable.functions.mistralai import chat_completions
|
4 |
from datetime import datetime
|
5 |
from textblob import TextBlob
|
|
|
6 |
import nltk
|
7 |
from nltk.tokenize import word_tokenize
|
8 |
from nltk.corpus import stopwords
|
9 |
import os
|
10 |
import getpass
|
11 |
+
import re
|
12 |
|
13 |
# Ensure necessary NLTK data is downloaded
|
14 |
nltk.download('punkt', quiet=True)
|
15 |
nltk.download('stopwords', quiet=True)
|
|
|
16 |
|
17 |
# Set up Mistral API key
|
18 |
if 'MISTRAL_API_KEY' not in os.environ:
|
|
|
37 |
average_words_per_sentence = words / sentences
|
38 |
return 206.835 - 1.015 * average_words_per_sentence
|
39 |
|
40 |
+
def run_inference_and_analysis(task, system_prompt, input_text, temperature, top_p, max_tokens, min_tokens, stop, random_seed, safe_prompt):
|
|
|
41 |
# Initialize Pixeltable
|
42 |
pxt.drop_table('mistral_prompts', ignore_errors=True)
|
43 |
t = pxt.create_table('mistral_prompts', {
|
44 |
+
'task': pxt.StringType(),
|
45 |
+
'system': pxt.StringType(),
|
46 |
+
'input_text': pxt.StringType(),
|
47 |
+
'timestamp': pxt.TimestampType(),
|
48 |
+
'temperature': pxt.FloatType(),
|
49 |
+
'top_p': pxt.FloatType(),
|
50 |
+
'max_tokens': pxt.IntType(),
|
51 |
+
'min_tokens': pxt.IntType(),
|
52 |
+
'stop': pxt.StringType(),
|
53 |
+
'random_seed': pxt.IntType(),
|
54 |
+
'safe_prompt': pxt.BoolType()
|
55 |
})
|
56 |
|
57 |
+
# Insert new row
|
58 |
t.insert([{
|
59 |
'task': task,
|
60 |
'system': system_prompt,
|
|
|
63 |
'temperature': temperature,
|
64 |
'top_p': top_p,
|
65 |
'max_tokens': max_tokens,
|
66 |
+
'min_tokens': min_tokens,
|
67 |
'stop': stop,
|
68 |
'random_seed': random_seed,
|
69 |
'safe_prompt': safe_prompt
|
|
|
80 |
'temperature': temperature,
|
81 |
'top_p': top_p,
|
82 |
'max_tokens': max_tokens if max_tokens is not None else 300,
|
83 |
+
'min_tokens': min_tokens,
|
84 |
'stop': stop.split(',') if stop else None,
|
85 |
'random_seed': random_seed,
|
86 |
'safe_prompt': safe_prompt
|
87 |
}
|
88 |
|
89 |
+
# Run inference with both models
|
90 |
+
t['open_mistral_nemo'] = chat_completions(model='open-mistral-nemo', **common_params)
|
91 |
+
t['mistral_medium'] = chat_completions(model='mistral-medium', **common_params)
|
92 |
|
93 |
# Extract responses
|
94 |
+
t['omn_response'] = t.open_mistral_nemo.choices[0].message.content
|
95 |
+
t['ml_response'] = t.mistral_medium.choices[0].message.content
|
96 |
|
97 |
+
# Run analysis
|
98 |
+
t['large_sentiment_score'] = get_sentiment_score(t.ml_response)
|
99 |
+
t['large_keywords'] = extract_keywords(t.ml_response)
|
100 |
+
t['large_readability_score'] = calculate_readability(t.ml_response)
|
101 |
+
t['open_sentiment_score'] = get_sentiment_score(t.omn_response)
|
102 |
+
t['open_keywords'] = extract_keywords(t.omn_response)
|
103 |
+
t['open_readability_score'] = calculate_readability(t.omn_response)
|
104 |
|
105 |
+
# Get results
|
106 |
results = t.select(
|
107 |
t.omn_response, t.ml_response,
|
108 |
t.large_sentiment_score, t.open_sentiment_score,
|
109 |
t.large_keywords, t.open_keywords,
|
110 |
t.large_readability_score, t.open_readability_score
|
111 |
).tail(1)
|
112 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
return (
|
114 |
results['omn_response'][0],
|
115 |
results['ml_response'][0],
|
|
|
118 |
results['large_keywords'][0],
|
119 |
results['open_keywords'][0],
|
120 |
results['large_readability_score'][0],
|
121 |
+
results['open_readability_score'][0]
|
|
|
|
|
|
|
|
|
122 |
)
|
123 |
|
124 |
def gradio_interface():
|
125 |
+
with gr.Blocks() as demo:
|
126 |
+
gr.Markdown("# LLM Prompt Studio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
|
|
128 |
with gr.Row():
|
129 |
with gr.Column():
|
130 |
+
# Input components
|
131 |
+
task = gr.Textbox(label="Task")
|
132 |
+
system_prompt = gr.Textbox(label="System Prompt", lines=3)
|
133 |
+
input_text = gr.Textbox(label="Input Text", lines=3)
|
134 |
+
|
135 |
+
with gr.Accordion("Advanced Settings", open=False):
|
136 |
+
temperature = gr.Slider(minimum=0, maximum=1, value=0.7, step=0.1, label="Temperature")
|
137 |
+
top_p = gr.Slider(minimum=0, maximum=1, value=0.9, step=0.1, label="Top P")
|
138 |
+
max_tokens = gr.Number(label="Max Tokens", value=300)
|
139 |
+
min_tokens = gr.Number(label="Min Tokens", value=None)
|
140 |
+
stop = gr.Textbox(label="Stop Sequences (comma-separated)")
|
141 |
+
random_seed = gr.Number(label="Random Seed", value=None)
|
142 |
+
safe_prompt = gr.Checkbox(label="Safe Prompt", value=False)
|
143 |
+
|
144 |
+
# Example prompts
|
145 |
+
examples = [
|
146 |
+
["Sentiment Analysis",
|
147 |
+
"You are an AI trained to analyze the sentiment of text. Provide a detailed analysis of the emotional tone, highlighting key phrases that indicate sentiment.",
|
148 |
+
"The new restaurant downtown exceeded all my expectations. The food was exquisite, the service impeccable, and the ambiance was perfect for a romantic evening. I can't wait to go back!",
|
149 |
+
0.3, 0.95, 200, None, "", None, False],
|
150 |
+
|
151 |
+
["Story Generation",
|
152 |
+
"You are a creative writer. Generate a short, engaging story based on the given prompt. Include vivid descriptions and an unexpected twist.",
|
153 |
+
"In a world where dreams are shared, a young girl discovers she can manipulate other people's dreams.",
|
154 |
+
0.9, 0.8, 500, 300, "The end", None, False]
|
155 |
+
]
|
156 |
+
|
157 |
+
gr.Examples(
|
158 |
+
examples=examples,
|
159 |
+
inputs=[
|
160 |
+
task, system_prompt, input_text,
|
161 |
+
temperature, top_p, max_tokens,
|
162 |
+
min_tokens, stop, random_seed,
|
163 |
+
safe_prompt
|
164 |
+
],
|
165 |
+
outputs=[
|
166 |
+
omn_response, ml_response,
|
167 |
+
large_sentiment, open_sentiment,
|
168 |
+
large_keywords, open_keywords,
|
169 |
+
large_readability, open_readability
|
170 |
+
],
|
171 |
+
fn=run_inference_and_analysis
|
172 |
+
)
|
173 |
+
|
174 |
+
submit_btn = gr.Button("Run Analysis")
|
175 |
|
176 |
with gr.Column():
|
177 |
+
# Output components
|
178 |
+
omn_response = gr.Textbox(label="Open-Mistral-Nemo Response")
|
179 |
+
ml_response = gr.Textbox(label="Mistral-Medium Response")
|
180 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
with gr.Row():
|
182 |
+
large_sentiment = gr.Number(label="Mistral-Medium Sentiment")
|
183 |
+
open_sentiment = gr.Number(label="Open-Mistral-Nemo Sentiment")
|
184 |
+
|
185 |
+
with gr.Row():
|
186 |
+
large_keywords = gr.Textbox(label="Mistral-Medium Keywords")
|
187 |
+
open_keywords = gr.Textbox(label="Open-Mistral-Nemo Keywords")
|
188 |
+
|
189 |
+
with gr.Row():
|
190 |
+
large_readability = gr.Number(label="Mistral-Medium Readability")
|
191 |
+
open_readability = gr.Number(label="Open-Mistral-Nemo Readability")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
submit_btn.click(
|
194 |
run_inference_and_analysis,
|
195 |
inputs=[
|
196 |
+
task, system_prompt, input_text,
|
197 |
+
temperature, top_p, max_tokens,
|
198 |
+
min_tokens, stop, random_seed,
|
199 |
+
safe_prompt
|
200 |
],
|
201 |
outputs=[
|
202 |
+
omn_response, ml_response,
|
203 |
+
large_sentiment, open_sentiment,
|
204 |
+
large_keywords, open_keywords,
|
205 |
+
large_readability, open_readability
|
|
|
206 |
]
|
207 |
)
|
208 |
|