Chris4K commited on
Commit
6cc2332
·
verified ·
1 Parent(s): bf8964e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -11
app.py CHANGED
@@ -4,6 +4,8 @@ import requests
4
 
5
  from PIL import Image
6
  from pydub.playback import Audio
 
 
7
 
8
  # From transformers import BertModel, BertTokenizer
9
  from transformers import HfAgent, load_tool
@@ -97,21 +99,42 @@ def handle_submission():
97
  print(response)
98
 
99
  # Display the agent's response
100
- if isinstance(response, str):
101
- # Display the text response
102
- print("text")
103
- st.write(response)
104
- elif isinstance(response, Image):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  # Display the image response
106
- print("image")
107
- st.image(response)
108
- elif isinstance(response, Audio):
109
- print("audio")
110
  # Handle audio response (replace with your audio rendering code)
111
- st.audio(response)
 
 
 
 
 
112
  else:
113
  # Handle unrecognized response type
114
- print("warning")
115
  st.warning("Unrecognized response type.")
116
 
117
 
 
4
 
5
  from PIL import Image
6
  from pydub.playback import Audio
7
+ from pydub import AudioSegment
8
+
9
 
10
  # From transformers import BertModel, BertTokenizer
11
  from transformers import HfAgent, load_tool
 
99
  print(response)
100
 
101
  # Display the agent's response
102
+ # if isinstance(response, str):
103
+ # # Display the text response
104
+ # print("text")
105
+ # st.write(response)
106
+ # elif isinstance(response, Image):
107
+ # # Display the image response
108
+ # # print("image")
109
+ # st.image(response)
110
+ # elif isinstance(response, Audio):
111
+ # print("audio")
112
+ # # Handle audio response (replace with your audio rendering code)
113
+ # st.audio(response)
114
+ # else:
115
+ # # Handle unrecognized response type
116
+ # print("warning")
117
+ # st.warning("Unrecognized response type.")
118
+ # Update the import statement for Audio
119
+
120
+ # ...
121
+
122
+ # Display the agent's response
123
+ if "image" in response:
124
  # Display the image response
125
+ image_data = base64.b64decode(response.split(",")[1])
126
+ img = Image.open(io.BytesIO(image_data))
127
+ st.image(img)
128
+ elif "audio" in response:
129
  # Handle audio response (replace with your audio rendering code)
130
+ audio_data = base64.b64decode(response.split(",")[1])
131
+ audio = AudioSegment.from_file(io.BytesIO(audio_data))
132
+ st.audio(audio)
133
+ elif "text" in response:
134
+ # Display the text response
135
+ st.write(response)
136
  else:
137
  # Handle unrecognized response type
 
138
  st.warning("Unrecognized response type.")
139
 
140