refactored ollama gui

This commit is contained in:
tcsenpai 2025-05-23 10:34:21 +02:00
parent b99f47320b
commit 51e5e5eefe

110
app.py
View File

@ -215,41 +215,23 @@ def create_interface():
value="Auto-detect", value="Auto-detect",
label="Language (optional)", label="Language (optional)",
) )
if OLLAMA_AVAILABLE:
with gr.Group(): with gr.Group():
summarize_checkbox = gr.Checkbox( summarize_checkbox = gr.Checkbox(
label="Generate Summary", value=False label="Generate Summary",
value=False,
interactive=OLLAMA_AVAILABLE,
) )
ollama_model_dropdown = gr.Dropdown( ollama_model_dropdown = gr.Dropdown(
choices=OLLAMA_MODELS, choices=(
value=DEFAULT_OLLAMA_MODEL, OLLAMA_MODELS
if OLLAMA_AVAILABLE
else ["No models available"]
),
value=(
DEFAULT_OLLAMA_MODEL if OLLAMA_AVAILABLE else None
),
label="Ollama Model", label="Ollama Model",
visible=False, interactive=OLLAMA_AVAILABLE,
)
def toggle_summary(checked):
if checked and not ollama.is_available():
gr.Warning(
"Ollama is not available. Please check your Ollama server."
)
return False
return checked
def update_model_visibility(visible):
if visible:
return gr.Dropdown.update(
visible=True, value=DEFAULT_OLLAMA_MODEL
)
return gr.Dropdown.update(visible=False)
summarize_checkbox.change(
fn=toggle_summary,
inputs=[summarize_checkbox],
outputs=[summarize_checkbox],
).then(
fn=update_model_visibility,
inputs=[summarize_checkbox],
outputs=[ollama_model_dropdown],
) )
transcribe_btn = gr.Button("Transcribe", variant="primary") transcribe_btn = gr.Button("Transcribe", variant="primary")
@ -284,16 +266,8 @@ def create_interface():
audio_input, audio_input,
model_dropdown, model_dropdown,
language_dropdown, language_dropdown,
( summarize_checkbox,
summarize_checkbox ollama_model_dropdown,
if OLLAMA_AVAILABLE
else gr.Checkbox(value=False)
),
(
ollama_model_dropdown
if OLLAMA_AVAILABLE
else gr.Dropdown(value=None)
),
], ],
outputs=[ outputs=[
output_text, output_text,
@ -331,41 +305,23 @@ def create_interface():
value="Auto-detect", value="Auto-detect",
label="Language (optional)", label="Language (optional)",
) )
if OLLAMA_AVAILABLE:
with gr.Group(): with gr.Group():
yt_summarize_checkbox = gr.Checkbox( yt_summarize_checkbox = gr.Checkbox(
label="Generate Summary", value=False label="Generate Summary",
value=False,
interactive=OLLAMA_AVAILABLE,
) )
yt_ollama_model_dropdown = gr.Dropdown( yt_ollama_model_dropdown = gr.Dropdown(
choices=OLLAMA_MODELS, choices=(
value=DEFAULT_OLLAMA_MODEL, OLLAMA_MODELS
if OLLAMA_AVAILABLE
else ["No models available"]
),
value=(
DEFAULT_OLLAMA_MODEL if OLLAMA_AVAILABLE else None
),
label="Ollama Model", label="Ollama Model",
visible=False, interactive=OLLAMA_AVAILABLE,
)
def toggle_yt_summary(checked):
if checked and not ollama.is_available():
gr.Warning(
"Ollama is not available. Please check your Ollama server."
)
return False
return checked
def update_yt_model_visibility(visible):
if visible:
return gr.Dropdown.update(
visible=True, value=DEFAULT_OLLAMA_MODEL
)
return gr.Dropdown.update(visible=False)
yt_summarize_checkbox.change(
fn=toggle_yt_summary,
inputs=[yt_summarize_checkbox],
outputs=[yt_summarize_checkbox],
).then(
fn=update_yt_model_visibility,
inputs=[yt_summarize_checkbox],
outputs=[yt_ollama_model_dropdown],
) )
yt_process_btn = gr.Button("Process Video", variant="primary") yt_process_btn = gr.Button("Process Video", variant="primary")
@ -399,16 +355,8 @@ def create_interface():
youtube_url, youtube_url,
yt_model_dropdown, yt_model_dropdown,
yt_language_dropdown, yt_language_dropdown,
( yt_summarize_checkbox,
yt_summarize_checkbox yt_ollama_model_dropdown,
if OLLAMA_AVAILABLE
else gr.Checkbox(value=False)
),
(
yt_ollama_model_dropdown
if OLLAMA_AVAILABLE
else gr.Dropdown(value=None)
),
], ],
outputs=[ outputs=[
yt_output_text, yt_output_text,
@ -428,7 +376,7 @@ def create_interface():
- Maximum audio duration is {MAX_DURATION // 60} minutes - Maximum audio duration is {MAX_DURATION // 60} minutes
- YouTube videos will first try to use available subtitles - YouTube videos will first try to use available subtitles
- If no subtitles are available, the video will be transcribed - If no subtitles are available, the video will be transcribed
{"- Ollama summarization is available for both local files and YouTube videos" if OLLAMA_AVAILABLE else ""} {"- Ollama summarization is available for both local files and YouTube videos" if OLLAMA_AVAILABLE else "- Ollama summarization is currently unavailable"}
### Status: ### Status:
- Device: {DEVICE} - Device: {DEVICE}