Spaces:
Running on T4
Running on T4
remove fallback_on_error
Browse files- src/generate.py +4 -14
src/generate.py
CHANGED
|
@@ -9,7 +9,7 @@ Hugging Face Space for Llama 3.2 3B Instruct) to generate natural-sounding
|
|
| 9 |
sentences that users can read aloud to give informed consent for voice cloning.
|
| 10 |
|
| 11 |
If the model call fails (e.g., due to rate limits or network issues),
|
| 12 |
-
an error is surfaced to the UI
|
| 13 |
"""
|
| 14 |
|
| 15 |
import os
|
|
@@ -68,13 +68,13 @@ def _extract_llama_text(result: Any) -> str:
|
|
| 68 |
return ""
|
| 69 |
|
| 70 |
|
| 71 |
-
def gen_sentence(
|
| 72 |
"""
|
| 73 |
Always generate a sentence via the LLM. UI may still pass a 'method' arg,
|
| 74 |
but it's ignored to keep the callback signature stable.
|
| 75 |
"""
|
| 76 |
try:
|
| 77 |
-
return gen_sentence_llm(audio_model_name=audio_model_name
|
| 78 |
except Exception as e:
|
| 79 |
# Show a helpful message directly in the Target sentence box
|
| 80 |
return f"[ERROR calling LLM] {type(e).__name__}: {e}"
|
|
@@ -83,8 +83,7 @@ def gen_sentence(_ignored_method="Llama 3.2 3B Instruct", audio_model_name="Chat
|
|
| 83 |
def gen_sentence_llm(
|
| 84 |
sentence_method: str = "Llama 3.2 3B Instruct",
|
| 85 |
audio_model_name: str = "Chatterbox",
|
| 86 |
-
*
|
| 87 |
-
fallback_on_error: bool = False # kept for signature parity; does nothing now
|
| 88 |
) -> str:
|
| 89 |
"""
|
| 90 |
Generate a consent sentence using the Llama 3.2 3B Instruct demo Space.
|
|
@@ -101,19 +100,11 @@ def gen_sentence_llm(
|
|
| 101 |
audio_model_name : str, optional
|
| 102 |
The name of the voice-cloning model to mention in the sentence.
|
| 103 |
Defaults to "Chatterbox".
|
| 104 |
-
fallback_on_error : bool, optional
|
| 105 |
-
If True, return a random fallback sentence instead of raising
|
| 106 |
-
an error when the Space call fails. Default is False for debugging.
|
| 107 |
|
| 108 |
Returns
|
| 109 |
-------
|
| 110 |
str
|
| 111 |
A clean, human-readable consent sentence.
|
| 112 |
-
|
| 113 |
-
Raises
|
| 114 |
-
------
|
| 115 |
-
Exception
|
| 116 |
-
Re-raises the underlying error if `fallback_on_error` is False.
|
| 117 |
"""
|
| 118 |
# Generate the full natural-language prompt that the LLM will receive
|
| 119 |
prompt = get_consent_generation_prompt(audio_model_name)
|
|
@@ -141,5 +132,4 @@ def gen_sentence_llm(
|
|
| 141 |
|
| 142 |
except Exception as e:
|
| 143 |
print(f"[gen_sentence_llm] Llama Space call failed: {type(e).__name__}: {e}")
|
| 144 |
-
# No local fallback anymore; surface the error to the UI.
|
| 145 |
raise
|
|
|
|
| 9 |
sentences that users can read aloud to give informed consent for voice cloning.
|
| 10 |
|
| 11 |
If the model call fails (e.g., due to rate limits or network issues),
|
| 12 |
+
an error is surfaced to the UI.
|
| 13 |
"""
|
| 14 |
|
| 15 |
import os
|
|
|
|
| 68 |
return ""
|
| 69 |
|
| 70 |
|
| 71 |
+
def gen_sentence(audio_model_name="Chatterbox"):
|
| 72 |
"""
|
| 73 |
Always generate a sentence via the LLM. UI may still pass a 'method' arg,
|
| 74 |
but it's ignored to keep the callback signature stable.
|
| 75 |
"""
|
| 76 |
try:
|
| 77 |
+
return gen_sentence_llm(audio_model_name=audio_model_name)
|
| 78 |
except Exception as e:
|
| 79 |
# Show a helpful message directly in the Target sentence box
|
| 80 |
return f"[ERROR calling LLM] {type(e).__name__}: {e}"
|
|
|
|
| 83 |
def gen_sentence_llm(
|
| 84 |
sentence_method: str = "Llama 3.2 3B Instruct",
|
| 85 |
audio_model_name: str = "Chatterbox",
|
| 86 |
+
*
|
|
|
|
| 87 |
) -> str:
|
| 88 |
"""
|
| 89 |
Generate a consent sentence using the Llama 3.2 3B Instruct demo Space.
|
|
|
|
| 100 |
audio_model_name : str, optional
|
| 101 |
The name of the voice-cloning model to mention in the sentence.
|
| 102 |
Defaults to "Chatterbox".
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
Returns
|
| 105 |
-------
|
| 106 |
str
|
| 107 |
A clean, human-readable consent sentence.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
"""
|
| 109 |
# Generate the full natural-language prompt that the LLM will receive
|
| 110 |
prompt = get_consent_generation_prompt(audio_model_name)
|
|
|
|
| 132 |
|
| 133 |
except Exception as e:
|
| 134 |
print(f"[gen_sentence_llm] Llama Space call failed: {type(e).__name__}: {e}")
|
|
|
|
| 135 |
raise
|