Update app.py
Browse files
app.py
CHANGED
|
@@ -1,101 +1,35 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
|
| 3 |
-
import requests
|
| 4 |
-
import json
|
| 5 |
-
import numpy as np
|
| 6 |
-
# from sklearn.metrics.pairwise import cosine_similarity
|
| 7 |
-
import pickle
|
| 8 |
import os
|
| 9 |
-
from
|
| 10 |
-
import ast
|
| 11 |
-
|
| 12 |
-
dd= os.getenv('funns')
|
| 13 |
-
|
| 14 |
-
exec(dd)
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
#######################
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
# # Generate interpretations
|
| 26 |
-
# all_interpretations = generate_interpretations(case)
|
| 27 |
-
# yield all_interpretations, gr.update() # Use gr.update() instead of gr.Textbox.update()
|
| 28 |
-
|
| 29 |
-
# # Prepare input for final answer
|
| 30 |
-
# # explanation_input = f'Case: \n\n{case}\n\nInterpretation: {all_interpretations}\n\nReferences: {reff}'
|
| 31 |
-
# explanation_input = f'Case: \n\n{case}\n\nInterpretation: {all_interpretations}'
|
| 32 |
-
# explanation_sys_prompt2 = f'{explanation_sys_prompt} \n\nReferences: {reff}'
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
# # Generate final answer
|
| 37 |
-
# f_answer = generate_text(explanation_input, explanation_sys_prompt2, temperature=0.2, model="gpt-4o-mini", max_tokens=3500)
|
| 38 |
-
|
| 39 |
-
# yield all_interpretations, f_answer
|
| 40 |
-
# else:
|
| 41 |
-
# yield "Please enter some text.", ""
|
| 42 |
-
|
| 43 |
-
# with gr.Blocks(title="GI Assist") as demo:
|
| 44 |
-
# gr.Markdown("# GI Assist")
|
| 45 |
-
# gr.Markdown("Enter your case and click submit.")
|
| 46 |
-
|
| 47 |
-
# with gr.Row():
|
| 48 |
-
# input_text = gr.Textbox(lines=5, placeholder="Enter your case here...")
|
| 49 |
-
|
| 50 |
-
# with gr.Row():
|
| 51 |
-
# submit_btn = gr.Button("Submit")
|
| 52 |
|
| 53 |
-
#
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
| 58 |
-
# process_input,
|
| 59 |
-
# inputs=[input_text],
|
| 60 |
-
# outputs=[interpretations_output, medical_opinion_output]
|
| 61 |
-
# )
|
| 62 |
-
|
| 63 |
-
# demo.queue()
|
| 64 |
-
# demo.launch()
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
def process_input(case):
|
| 75 |
-
if case.strip():
|
| 76 |
-
all_interpretations = generate_interpretations(case)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
explanation_input = f'Case: \n\n{case}\n\nInterpretation: {all_interpretations}'
|
| 80 |
-
explanation_sys_prompt2 = f'{explanation_sys_prompt} \n\nReferences: {reff}'
|
| 81 |
-
|
| 82 |
-
f_answer = generate_text(explanation_input, explanation_sys_prompt2, temperature=0.2, model="gpt-4o-mini", max_tokens=3500)
|
| 83 |
-
|
| 84 |
-
return all_interpretations, f_answer
|
| 85 |
-
else:
|
| 86 |
-
return "Please enter some text.", ""
|
| 87 |
|
| 88 |
# Create the Gradio interface
|
| 89 |
iface = gr.Interface(
|
| 90 |
-
fn=
|
| 91 |
-
inputs=gr.
|
| 92 |
-
outputs=
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
],
|
| 96 |
-
title="GI Assist",
|
| 97 |
-
description="Enter your case and click submit to generate a response using ChatGPT."
|
| 98 |
)
|
| 99 |
|
| 100 |
-
# Launch the
|
| 101 |
-
iface.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import os
|
| 3 |
+
from groq import Groq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# Initialize the Groq client
|
| 6 |
+
client = Groq(api_key=os.environ["keko"])
|
|
|
|
| 7 |
|
| 8 |
+
def transcribe_audio(audio_file):
|
| 9 |
+
if audio_file is None:
|
| 10 |
+
return "No audio file provided."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Create a transcription of the audio file
|
| 13 |
+
with open(audio_file, "rb") as file:
|
| 14 |
+
transcription = client.audio.transcriptions.create(
|
| 15 |
+
file=(audio_file, file.read()),
|
| 16 |
+
model="distil-whisper-large-v3-en",
|
| 17 |
+
prompt="Specify context or spelling",
|
| 18 |
+
response_format="json",
|
| 19 |
+
language="en",
|
| 20 |
+
temperature=0.0
|
| 21 |
+
)
|
| 22 |
|
| 23 |
+
return transcription.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# Create the Gradio interface
|
| 26 |
iface = gr.Interface(
|
| 27 |
+
fn=transcribe_audio,
|
| 28 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 29 |
+
outputs="text",
|
| 30 |
+
title="Audio Transcription with Groq",
|
| 31 |
+
description="Record audio and get its transcription using Groq's speech-to-text API."
|
|
|
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
+
# Launch the interface
|
| 35 |
+
iface.launch()
|