bai4578 commited on
Commit
22cb4df
·
verified ·
1 Parent(s): e1ae669

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -91
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 tqdm import tqdm
10
- import ast
11
-
12
- dd= os.getenv('funns')
13
-
14
- exec(dd)
15
-
16
-
17
 
18
- ######################
19
- # App
20
- #######################
21
 
22
-
23
- # def process_input(case):
24
- # if case.strip():
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
- # with gr.Row():
54
- # interpretations_output = gr.Textbox(label="Interpretations:", lines=6)
55
- # medical_opinion_output = gr.Textbox(label="Medical opinion:", lines=10)
 
 
 
 
 
 
 
56
 
57
- # submit_btn.click(
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=process_input,
91
- inputs=gr.Textbox(lines=5, placeholder="Enter your case here..."),
92
- outputs=[
93
- gr.Textbox(label="Interpretations:", lines=6),
94
- gr.Textbox(label="Medical opinion:", lines=10)
95
- ],
96
- title="GI Assist",
97
- description="Enter your case and click submit to generate a response using ChatGPT."
98
  )
99
 
100
- # Launch the app
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()