Mawube commited on
Commit
216ee15
·
unverified ·
1 Parent(s): ed89f9e

Disable audio generation

Browse files
Files changed (3) hide show
  1. main.py +7 -4
  2. requirements.txt +1 -1
  3. utils/audio_generation.py +22 -1
main.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI, HTTPException, UploadFile, File
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import JSONResponse
4
  from utils.palmoil_classification import AfroPalmModel
@@ -69,8 +69,9 @@ async def predict(image_request: ImageRequest):
69
  logging.debug(f"Prediction: {prediction}, Confidence: {confidence*100:.2f}%")
70
 
71
  # Generate audio
72
- audio_generation = AudioGeneration(prediction=prediction, confidence=confidence*100, language=image_request.lang)
73
- translated_text = audio_generation.ghanaian_language_translator()
 
74
 
75
  else:
76
  logging.info("Image is not a red palm oil")
@@ -86,8 +87,10 @@ async def predict(image_request: ImageRequest):
86
  return {
87
  "status": "success",
88
  "result": prediction,
89
- "confidence": f"{confidence*100:.2f}"
 
90
  }
 
91
 
92
  except Exception as e:
93
  logging.error(e)
 
1
+ from fastapi import FastAPI, HTTPException, FileResponse
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.responses import JSONResponse
4
  from utils.palmoil_classification import AfroPalmModel
 
69
  logging.debug(f"Prediction: {prediction}, Confidence: {confidence*100:.2f}%")
70
 
71
  # Generate audio
72
+ # audio_generation = AudioGeneration(prediction=prediction, confidence=confidence*100, language=image_request.lang)
73
+ # translated_text = audio_generation.ghanaian_language_translator()
74
+ # translated_text_audiofile = audio_generation.text_to_audio(translated_text)
75
 
76
  else:
77
  logging.info("Image is not a red palm oil")
 
87
  return {
88
  "status": "success",
89
  "result": prediction,
90
+ "confidence": f"{confidence*100:.2f}",
91
+
92
  }
93
+ # "audio": FileResponse(path='final_result.wav', media_type="audio/mpeg", filename="final_result.wav")
94
 
95
  except Exception as e:
96
  logging.error(e)
requirements.txt CHANGED
@@ -7,4 +7,4 @@ torch
7
  torchvision
8
  opencv-python
9
  tensorflow
10
- roboflow
 
7
  torchvision
8
  opencv-python
9
  tensorflow
10
+ roboflow
utils/audio_generation.py CHANGED
@@ -1,5 +1,7 @@
1
  import requests
2
  import logging
 
 
3
 
4
  class AudioGeneration:
5
  """
@@ -64,4 +66,23 @@ class AudioGeneration:
64
  translated_text = response['data'][0]
65
  logging.debug(f"Translated text:{translated_text}")
66
 
67
- return translated_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import requests
2
  import logging
3
+ from gradio_client import Client
4
+
5
 
6
  class AudioGeneration:
7
  """
 
66
  translated_text = response['data'][0]
67
  logging.debug(f"Translated text:{translated_text}")
68
 
69
+ return translated_text
70
+
71
+ def text_to_audio(self,text):
72
+ """
73
+ Convert the translated text to audio
74
+ :param text: translated text
75
+ :return: audio file
76
+ """
77
+ logging.info("Converting text to audio")
78
+
79
+ client = Client("https://softwarearoma-ghanalanguageaudiosynthesizer.hf.space/--replicas/0t7ah/")
80
+ result = client.predict(
81
+ self.selected_languages[self.language],
82
+ text,
83
+ api_name="/predict"
84
+ )
85
+
86
+ logging.debug(f"Audio file: {result[0]}")
87
+
88
+ return result[0]