Upload app.py
Browse files
app.py
CHANGED
|
@@ -4,9 +4,16 @@ from torch import exp
|
|
| 4 |
from inflections_funcs import start_model, make_beams, get_beam_tokens, calculate_score_vectors
|
| 5 |
|
| 6 |
# Global model initialization
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def generate_beam_html(index, all_beams_data, dark_mode):
|
| 12 |
"""
|
|
@@ -63,6 +70,9 @@ def predict(prompt, dark_mode):
|
|
| 63 |
"""
|
| 64 |
Generates responses for 5 beams and returns the first beam's visualization and visibility for controls.
|
| 65 |
"""
|
|
|
|
|
|
|
|
|
|
| 66 |
# Generate beams
|
| 67 |
generated_dicts, transcription = make_beams(model, processor, prompt)
|
| 68 |
|
|
@@ -110,7 +120,7 @@ with gr.Blocks() as demo:
|
|
| 110 |
''')
|
| 111 |
|
| 112 |
with gr.Column():
|
| 113 |
-
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...", lines=
|
| 114 |
dark_mode_toggle = gr.Checkbox(label="Dark Mode", value=True)
|
| 115 |
submit_btn = gr.Button("Generate")
|
| 116 |
|
|
|
|
| 4 |
from inflections_funcs import start_model, make_beams, get_beam_tokens, calculate_score_vectors
|
| 5 |
|
| 6 |
# Global model initialization
|
| 7 |
+
model = None
|
| 8 |
+
processor = None
|
| 9 |
+
|
| 10 |
+
def initialize_model():
|
| 11 |
+
global model, processor
|
| 12 |
+
if model is None:
|
| 13 |
+
print("Loading model...")
|
| 14 |
+
model, processor = start_model()
|
| 15 |
+
print("Model loaded.")
|
| 16 |
+
return model, processor
|
| 17 |
|
| 18 |
def generate_beam_html(index, all_beams_data, dark_mode):
|
| 19 |
"""
|
|
|
|
| 70 |
"""
|
| 71 |
Generates responses for 5 beams and returns the first beam's visualization and visibility for controls.
|
| 72 |
"""
|
| 73 |
+
# Ensure model is loaded within the GPU context to avoid ZeroGPU CUDA init errors
|
| 74 |
+
model, processor = initialize_model()
|
| 75 |
+
|
| 76 |
# Generate beams
|
| 77 |
generated_dicts, transcription = make_beams(model, processor, prompt)
|
| 78 |
|
|
|
|
| 120 |
''')
|
| 121 |
|
| 122 |
with gr.Column():
|
| 123 |
+
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt here...", lines=1, show_label=True)
|
| 124 |
dark_mode_toggle = gr.Checkbox(label="Dark Mode", value=True)
|
| 125 |
submit_btn = gr.Button("Generate")
|
| 126 |
|