Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,11 @@ import numpy as np
|
|
| 14 |
from PIL import Image
|
| 15 |
import edge_tts
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
from transformers import (
|
| 18 |
AutoModelForCausalLM,
|
| 19 |
AutoTokenizer,
|
|
@@ -24,14 +29,6 @@ from transformers import (
|
|
| 24 |
from transformers.image_utils import load_image
|
| 25 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
| 26 |
|
| 27 |
-
# Load the reasoning model interface from sambanova_gradio
|
| 28 |
-
try:
|
| 29 |
-
import sambanova_gradio
|
| 30 |
-
reasoning_interface = gr.load("DeepSeek-R1-Distill-Llama-70B", src=sambanova_gradio.registry, accept_token=True)
|
| 31 |
-
except Exception as e:
|
| 32 |
-
reasoning_interface = None
|
| 33 |
-
print("Reasoning model could not be loaded:", e)
|
| 34 |
-
|
| 35 |
MAX_MAX_NEW_TOKENS = 2048
|
| 36 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
| 37 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
|
@@ -194,8 +191,8 @@ def generate(
|
|
| 194 |
):
|
| 195 |
text = input_dict["text"]
|
| 196 |
files = input_dict.get("files", [])
|
| 197 |
-
lower_text = text.lower().strip()
|
| 198 |
|
|
|
|
| 199 |
# Check if the prompt is an image generation command using model flags.
|
| 200 |
if (lower_text.startswith("@lightningv5") or
|
| 201 |
lower_text.startswith("@lightningv4") or
|
|
@@ -248,16 +245,14 @@ def generate(
|
|
| 248 |
yield gr.Image(image_path)
|
| 249 |
return
|
| 250 |
|
| 251 |
-
# New reasoning
|
| 252 |
elif lower_text.startswith("@reasoning"):
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
result = reasoning_interface.predict(prompt_clean)
|
| 260 |
-
yield result
|
| 261 |
return
|
| 262 |
|
| 263 |
# Otherwise, handle text/chat (and TTS) generation.
|
|
|
|
| 14 |
from PIL import Image
|
| 15 |
import edge_tts
|
| 16 |
|
| 17 |
+
import sambanova_gradio
|
| 18 |
+
# Load the reasoning model from sambanova_gradio.
|
| 19 |
+
# This returns a callable interface for inference.
|
| 20 |
+
reasoning_model = gr.load("DeepSeek-R1-Distill-Llama-70B", src=sambanova_gradio.registry, accept_token=True)
|
| 21 |
+
|
| 22 |
from transformers import (
|
| 23 |
AutoModelForCausalLM,
|
| 24 |
AutoTokenizer,
|
|
|
|
| 29 |
from transformers.image_utils import load_image
|
| 30 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
MAX_MAX_NEW_TOKENS = 2048
|
| 33 |
DEFAULT_MAX_NEW_TOKENS = 1024
|
| 34 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
|
|
|
| 191 |
):
|
| 192 |
text = input_dict["text"]
|
| 193 |
files = input_dict.get("files", [])
|
|
|
|
| 194 |
|
| 195 |
+
lower_text = text.lower().strip()
|
| 196 |
# Check if the prompt is an image generation command using model flags.
|
| 197 |
if (lower_text.startswith("@lightningv5") or
|
| 198 |
lower_text.startswith("@lightningv4") or
|
|
|
|
| 245 |
yield gr.Image(image_path)
|
| 246 |
return
|
| 247 |
|
| 248 |
+
# New reasoning branch.
|
| 249 |
elif lower_text.startswith("@reasoning"):
|
| 250 |
+
# Remove the reasoning flag and clean the prompt.
|
| 251 |
+
prompt_clean = re.sub(r"@reasoning", "", text, flags=re.IGNORECASE).strip().strip('"')
|
| 252 |
+
yield "Processing reasoning request..."
|
| 253 |
+
# Call the reasoning model (this call might be synchronous; adjust if needed).
|
| 254 |
+
reasoning_response = reasoning_model(prompt_clean)
|
| 255 |
+
yield reasoning_response
|
|
|
|
|
|
|
| 256 |
return
|
| 257 |
|
| 258 |
# Otherwise, handle text/chat (and TTS) generation.
|