iSushant commited on
Commit
0ae90bc
·
verified ·
1 Parent(s): fef1283

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -17
app.py CHANGED
@@ -1,15 +1,13 @@
1
  import gradio as gr
2
  import google.generativeai as genai
3
  from PIL import Image
4
- import io
5
- from gtts import gTTS
6
 
7
  # Configure Gemini API (hardcoded as you requested)
8
  genai.configure(api_key="AIzaSyB6JYzYNfi8ak7g6526raHQ08YPMiC5Wic")
9
 
10
  def interpret_sign(image: Image.Image):
11
  if image is None:
12
- return "Please upload or capture an image.", None
13
 
14
  try:
15
  # Prepare prompt
@@ -34,28 +32,19 @@ def interpret_sign(image: Image.Image):
34
  if not text:
35
  text = getattr(response, "text", None)
36
  if not text or not text.strip():
37
- return "Could not interpret the sign.", None
38
 
39
- # Generate TTS audio
40
- tts = gTTS(text=text, lang='en', slow=False)
41
- audio_fp = io.BytesIO()
42
- tts.write_to_fp(audio_fp)
43
- audio_fp.seek(0)
44
-
45
- return text, (audio_fp, "audio/mp3")
46
  except Exception as e:
47
- return f"Error: {str(e)}", None
48
 
49
  # Gradio UI
50
  demo = gr.Interface(
51
  fn=interpret_sign,
52
  inputs=gr.Image(label="Sign Image", sources=["upload", "webcam"], type="pil"),
53
- outputs=[
54
- gr.Textbox(label="Interpretation"),
55
- gr.Audio(label="Audio", type="filepath")
56
- ],
57
  title="Sign Language Interpreter",
58
- description="Upload or capture an image of a sign language gesture. The app will interpret the sign and provide an audio output."
59
  )
60
 
61
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import google.generativeai as genai
3
  from PIL import Image
 
 
4
 
5
  # Configure Gemini API (hardcoded as you requested)
6
  genai.configure(api_key="AIzaSyB6JYzYNfi8ak7g6526raHQ08YPMiC5Wic")
7
 
8
  def interpret_sign(image: Image.Image):
9
  if image is None:
10
+ return "Please upload or capture an image."
11
 
12
  try:
13
  # Prepare prompt
 
32
  if not text:
33
  text = getattr(response, "text", None)
34
  if not text or not text.strip():
35
+ return "Could not interpret the sign."
36
 
37
+ return text
 
 
 
 
 
 
38
  except Exception as e:
39
+ return f"Error: {str(e)}"
40
 
41
  # Gradio UI
42
  demo = gr.Interface(
43
  fn=interpret_sign,
44
  inputs=gr.Image(label="Sign Image", sources=["upload", "webcam"], type="pil"),
45
+ outputs=gr.Textbox(label="Interpretation"),
 
 
 
46
  title="Sign Language Interpreter",
47
+ description="Upload or capture an image of a sign language gesture. The app will interpret the sign."
48
  )
49
 
50
  if __name__ == "__main__":