Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
img = img.convert("RGB")
|
| 17 |
-
img = img.resize(IMG_SIZE)
|
| 18 |
-
img_array = keras_image.img_to_array(img)
|
| 19 |
-
img_array = np.expand_dims(img_array, axis=0) / 255.0
|
| 20 |
-
preds = model.predict(img_array)
|
| 21 |
-
idx = np.argmax(preds)
|
| 22 |
-
severity = float(np.max(preds))
|
| 23 |
-
return f"Disease: {disease_map[idx]}\nSeverity: {severity:.2f}\nRecommendation: {rec_map[idx]}"
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
# Suppress TensorFlow info logs
|
| 3 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # Hide INFO & WARNING, only show errors
|
| 4 |
+
# Optional: disable oneDNN logs if you want completely consistent float ops
|
| 5 |
+
# os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 6 |
+
|
| 7 |
import gradio as gr
|
| 8 |
+
from TTS.api import TTS
|
| 9 |
+
|
| 10 |
+
# Initialize Coqui TTS model (downloaded once and cached)
|
| 11 |
+
# Replace with any model name from https://huggingface.co/coqui-ai
|
| 12 |
+
# "tts_models/en/ljspeech/tacotron2-DDC" is small and works offline
|
| 13 |
+
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
|
| 14 |
|
| 15 |
+
def generate_speech(text):
|
| 16 |
+
"""
|
| 17 |
+
Takes text input and generates speech audio using Coqui TTS.
|
| 18 |
+
Returns the path to the audio file for Gradio playback.
|
| 19 |
+
"""
|
| 20 |
+
if not text.strip():
|
| 21 |
+
return None
|
| 22 |
+
output_path = "output.wav"
|
| 23 |
+
# Generate speech and save to file
|
| 24 |
+
tts.tts_to_file(text=text, file_path=output_path)
|
| 25 |
+
return output_path
|
| 26 |
|
| 27 |
+
# Simple Gradio UI
|
| 28 |
+
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("# Offline Coqui TTS (Hugging Face Space)")
|
| 30 |
+
gr.Markdown("Enter text below and hear it synthesized offline using Coqui TTS.")
|
| 31 |
+
|
| 32 |
+
with gr.Row():
|
| 33 |
+
text_input = gr.Textbox(label="Enter Text", placeholder="Type something...", lines=2)
|
| 34 |
+
with gr.Row():
|
| 35 |
+
speak_button = gr.Button("Generate Speech")
|
| 36 |
+
with gr.Row():
|
| 37 |
+
audio_output = gr.Audio(label="Generated Audio", type="filepath")
|
| 38 |
|
| 39 |
+
speak_button.click(fn=generate_speech, inputs=text_input, outputs=audio_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
# Launch Gradio app (port/host auto-managed by HF Spaces)
|
| 43 |
+
demo.launch()
|