Spaces:
Runtime error
Runtime error
added tabs
Browse files
app.py
CHANGED
@@ -10,7 +10,7 @@ import json
|
|
10 |
import dotenv
|
11 |
from scipy.io.wavfile import write
|
12 |
import PIL
|
13 |
-
from openai import OpenAI
|
14 |
dotenv.load_dotenv()
|
15 |
|
16 |
seamless_client = Client("facebook/seamless_m4t")
|
@@ -22,7 +22,6 @@ def process_speech(audio):
|
|
22 |
"""
|
23 |
processing sound using seamless_m4t
|
24 |
"""
|
25 |
-
print("running audio ... \n audio_value is", audio)
|
26 |
audio_name = f"{np.random.randint(0, 100)}.wav"
|
27 |
sr, data = audio
|
28 |
write(audio_name, sr, data.astype(np.int16))
|
@@ -220,69 +219,98 @@ def convert_to_markdown(vectara_response_json):
|
|
220 |
# Main function to handle the Gradio interface logic
|
221 |
|
222 |
|
223 |
-
def process_and_query(text=None
|
224 |
try:
|
225 |
# augment the prompt before feeding it to vectara
|
226 |
text = "the user asks the following to his health adviser " + text
|
227 |
# If an image is provided, process it with OpenAI and use the response as the text query for Vectara
|
228 |
-
if image is not None:
|
229 |
-
|
230 |
-
|
231 |
-
if audio is not None:
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
|
236 |
|
237 |
# Now, use the text (either provided by the user or obtained from OpenAI) to query Vectara
|
238 |
vectara_response_json = query_vectara(text)
|
239 |
markdown_output = convert_to_markdown(vectara_response_json)
|
240 |
-
client = OpenAI()
|
241 |
-
prompt ="Answer in the same language, write it better, more understandable and shorter:"
|
242 |
-
markdown_output_final = markdown_output
|
243 |
-
|
244 |
-
completion = client.chat.completions.create(
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
)
|
251 |
-
final_response= completion.choices[0].message.content
|
252 |
-
return
|
253 |
except Exception as e:
|
254 |
return str(e)
|
255 |
|
256 |
|
257 |
# Define the Gradio interface
|
258 |
-
iface = gr.Interface(
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
iface.launch()
|
|
|
10 |
import dotenv
|
11 |
from scipy.io.wavfile import write
|
12 |
import PIL
|
13 |
+
# from openai import OpenAI
|
14 |
dotenv.load_dotenv()
|
15 |
|
16 |
seamless_client = Client("facebook/seamless_m4t")
|
|
|
22 |
"""
|
23 |
processing sound using seamless_m4t
|
24 |
"""
|
|
|
25 |
audio_name = f"{np.random.randint(0, 100)}.wav"
|
26 |
sr, data = audio
|
27 |
write(audio_name, sr, data.astype(np.int16))
|
|
|
219 |
# Main function to handle the Gradio interface logic
|
220 |
|
221 |
|
222 |
+
def process_and_query(text=None):
|
223 |
try:
|
224 |
# augment the prompt before feeding it to vectara
|
225 |
text = "the user asks the following to his health adviser " + text
|
226 |
# If an image is provided, process it with OpenAI and use the response as the text query for Vectara
|
227 |
+
# if image is not None:
|
228 |
+
# text = process_image(image)
|
229 |
+
# return "**Summary:** "+text
|
230 |
+
# if audio is not None:
|
231 |
+
# text = process_speech(audio)
|
232 |
+
# # augment the prompt before feeding it to vectara
|
233 |
+
# text = "the user asks the following to his health adviser " + text
|
234 |
|
235 |
|
236 |
# Now, use the text (either provided by the user or obtained from OpenAI) to query Vectara
|
237 |
vectara_response_json = query_vectara(text)
|
238 |
markdown_output = convert_to_markdown(vectara_response_json)
|
239 |
+
# client = OpenAI()
|
240 |
+
# prompt ="Answer in the same language, write it better, more understandable and shorter:"
|
241 |
+
# markdown_output_final = markdown_output
|
242 |
+
|
243 |
+
# completion = client.chat.completions.create(
|
244 |
+
# model="gpt-3.5-turbo",
|
245 |
+
# messages=[
|
246 |
+
# {"role": "system", "content": prompt},
|
247 |
+
# {"role": "user", "content": markdown_output_final}
|
248 |
+
# ]
|
249 |
+
# )
|
250 |
+
# final_response= completion.choices[0].message.content
|
251 |
+
return markdown_output
|
252 |
except Exception as e:
|
253 |
return str(e)
|
254 |
|
255 |
|
256 |
# Define the Gradio interface
|
257 |
+
# iface = gr.Interface(
|
258 |
+
# fn=process_and_query,
|
259 |
+
# inputs=[
|
260 |
+
# gr.Textbox(label="Input Text"),
|
261 |
+
# gr.Image(label="Upload Image"),
|
262 |
+
# gr.Audio(label="talk in french",
|
263 |
+
# sources=["microphone"]),
|
264 |
+
# ],
|
265 |
+
# outputs=[gr.Markdown(label="Output Text")],
|
266 |
+
# title="👋🏻Welcome to ⚕🗣️😷MultiMed - Access Chat ⚕🗣️😷",
|
267 |
+
# description='''
|
268 |
+
# ### How To Use ⚕🗣️😷MultiMed⚕:
|
269 |
+
# #### 🗣️📝Interact with ⚕🗣️😷MultiMed⚕ in any language using audio or text!
|
270 |
+
# #### 🗣️📝 This is an educational and accessible conversational tool to improve wellness and sanitation in support of public health.
|
271 |
+
# #### 📚🌟💼 The knowledge base is composed of publicly available medical and health sources in multiple languages. We also used [Kelvalya/MedAware](https://huggingface.co/datasets/keivalya/MedQuad-MedicalQnADataset) that we processed and converted to HTML. The quality of the answers depends on the quality of the dataset, so if you want to see some data represented here, do [get in touch](https://discord.gg/GWpVpekp). You can also use 😷MultiMed⚕️ on your own data & in your own way by cloning this space. 🧬🔬🔍 Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/TeamTonic/MultiMed?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
|
272 |
+
# #### Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [Discord](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [PolyGPT](https://github.com/tonic-ai/polygpt-alpha)"
|
273 |
+
# ''',
|
274 |
+
# theme='ParityError/Anime',
|
275 |
+
# examples=[
|
276 |
+
# ["What is the proper treatment for buccal herpes?"],
|
277 |
+
# ["Male, 40 presenting with swollen glands and a rash"],
|
278 |
+
# ["How does cellular metabolism work TCA cycle"],
|
279 |
+
# ["What special care must be provided to children with chicken pox?"],
|
280 |
+
# ["When and how often should I wash my hands ?"],
|
281 |
+
# ["بکل ہرپس کا صحیح علاج کیا ہے؟"],
|
282 |
+
# ["구강 헤르페스의 적절한 치료법은 무엇입니까?"],
|
283 |
+
# ["Je, ni matibabu gani sahihi kwa herpes ya buccal?"],
|
284 |
+
# ],
|
285 |
+
# )
|
286 |
+
|
287 |
+
welcome_message = """
|
288 |
+
# 👋🏻Welcome to ⚕🗣️😷MultiMed - Access Chat ⚕🗣️😷
|
289 |
+
### How To Use ⚕🗣️😷MultiMed⚕:
|
290 |
+
#### 🗣️📝Interact with ⚕🗣️😷MultiMed⚕ in any language using audio or text!
|
291 |
+
#### 🗣️📝 This is an educational and accessible conversational tool to improve wellness and sanitation in support of public health.
|
292 |
+
#### 📚🌟💼 The knowledge base is composed of publicly available medical and health sources in multiple languages. We also used [Kelvalya/MedAware](https://huggingface.co/datasets/keivalya/MedQuad-MedicalQnADataset) that we processed and converted to HTML. The quality of the answers depends on the quality of the dataset, so if you want to see some data represented here, do [get in touch](https://discord.gg/GWpVpekp). You can also use 😷MultiMed⚕️ on your own data & in your own way by cloning this space. 🧬🔬🔍 Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/TeamTonic/MultiMed?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
|
293 |
+
#### Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [Discord](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [PolyGPT](https://github.com/tonic-ai/polygpt-alpha)"
|
294 |
+
"""
|
295 |
+
|
296 |
+
with gr.Blocks(theme='ParityError/Anime') as iface :
|
297 |
+
gr.Markdown(welcome_message)
|
298 |
+
with gr.Tab("text summarization"):
|
299 |
+
text_input = gr.Textbox(label="input text",lines=5)
|
300 |
+
text_output = gr.Markdown(label="output text")
|
301 |
+
text_button = gr.Button("process text")
|
302 |
+
with gr.Tab("image identification"):
|
303 |
+
image_input = gr.Image(label="upload image")
|
304 |
+
image_output = gr.Markdown(label="output text")
|
305 |
+
image_button = gr.Button("process image")
|
306 |
+
with gr.Tab("speech to text translation"):
|
307 |
+
audio_input = gr.Audio(label="talk in french",
|
308 |
+
sources=["microphone"])
|
309 |
+
audio_output = gr.Markdown(label="output text")
|
310 |
+
audio_button = gr.Button("process audio")
|
311 |
+
text_button.click(process_and_query, inputs=text_input, outputs=text_output)
|
312 |
+
image_button.click(process_image, inputs=image_input, outputs=image_output)
|
313 |
+
audio_button.click(process_speech, inputs=audio_input, outputs=audio_output)
|
314 |
+
|
315 |
|
316 |
iface.launch()
|