Srikesh commited on
Commit
0a4e34a
·
verified ·
1 Parent(s): 43967e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -20
app.py CHANGED
@@ -1,25 +1,43 @@
 
 
 
 
 
 
1
  import gradio as gr
2
- from tensorflow.keras.models import load_model
3
- from tensorflow.keras.preprocessing import image as keras_image
4
- from PIL import Image
5
- import numpy as np
6
- import requests
7
- import io
8
 
9
- model = load_model("plant_disease_model.h5")
 
 
 
 
 
 
 
 
 
 
10
 
11
- disease_map = {0: "Powdery Mildew", 1: "Leaf Spot", 2: "Healthy"}
12
- rec_map = {0: "Apply fungicide", 1: "Remove affected leaves", 2: "No action needed"}
13
- IMG_SIZE = (224, 224)
 
 
 
 
 
 
 
 
14
 
15
- def predict_leaf_disease(img):
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
- iface = gr.Interface(fn=predict_leaf_disease, inputs=gr.Image(type="pil"), outputs="text")
 
 
 
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()