arteeguz commited on
Commit
764cb13
·
1 Parent(s): 0b400a0

fixed audio?

Browse files
Files changed (2) hide show
  1. 430.jpeg +0 -0
  2. app.py +15 -16
430.jpeg DELETED
Binary file (205 kB)
 
app.py CHANGED
@@ -19,21 +19,18 @@ def text_to_speech(message):
19
  API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
20
  headers = {"Authorization": f"Bearer {HUGGINGFACE_API_TOKEN}"}
21
  payloads = {
22
- "inputs": message
23
  }
24
 
25
  response = requests.post(API_URL, headers=headers, json=payloads)
26
- if response.status_code == 200:
27
- # Return the audio content directly
28
- return response.content
29
- else:
30
- # Handle errors or return a default error message/audio
31
- return None
32
-
33
  def main():
34
  st.set_page_config(page_title="Image to Text", page_icon="🎙️")
35
 
36
  st.header("Image to Text")
 
37
  image = "narrator.jpeg"
38
  left_co, cent_co, last_co = st.columns(3)
39
  with cent_co:
@@ -41,17 +38,19 @@ def main():
41
  uploaded_file = st.file_uploader("Choose an image: ", type=["jpg", "jpeg", "png"])
42
 
43
  if uploaded_file is not None:
 
44
  bytes_data = uploaded_file.getvalue()
45
  with open(uploaded_file.name, "wb") as file:
46
  file.write(bytes_data)
47
- st.image(uploaded_file, caption='Uploaded image', use_column_width=True)
48
- scenario = img_to_text(uploaded_file.name)
49
-
50
- audio_content = text_to_speech(scenario)
51
- if audio_content:
52
- st.audio(audio_content, format="audio/flac")
53
- else:
54
- st.error("Failed to generate audio.")
 
55
 
56
  if __name__== "__main__":
57
  main()
 
19
  API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
20
  headers = {"Authorization": f"Bearer {HUGGINGFACE_API_TOKEN}"}
21
  payloads = {
22
+ "inputs":message
23
  }
24
 
25
  response = requests.post(API_URL, headers=headers, json=payloads)
26
+ with open('audio.flac', 'wb') as file:
27
+ file.write(response.content)
28
+
 
 
 
 
29
  def main():
30
  st.set_page_config(page_title="Image to Text", page_icon="🎙️")
31
 
32
  st.header("Image to Text")
33
+ # Image.
34
  image = "narrator.jpeg"
35
  left_co, cent_co, last_co = st.columns(3)
36
  with cent_co:
 
38
  uploaded_file = st.file_uploader("Choose an image: ", type=["jpg", "jpeg", "png"])
39
 
40
  if uploaded_file is not None:
41
+ print(uploaded_file)
42
  bytes_data = uploaded_file.getvalue()
43
  with open(uploaded_file.name, "wb") as file:
44
  file.write(bytes_data)
45
+ st.image(uploaded_file, caption='Uploaded image', use_column_width=True)
46
+ scenario=img_to_text(uploaded_file.name)
47
+ text_to_speech(scenario)
48
+
49
+ with st.expander("scenatio"):
50
+ st.write(scenario)
51
+
52
+ st.audio("audio.flac")
53
+
54
 
55
  if __name__== "__main__":
56
  main()