spriambada3 commited on
Commit
d308880
·
1 Parent(s): 5f358d0

try groq audio again

Browse files
Files changed (1) hide show
  1. app.py +12 -36
app.py CHANGED
@@ -13,19 +13,6 @@ if not GROQ_API_KEY:
13
  raise ValueError("GROQ API NOT FOUND!")
14
  gclient = Groq(api_key=GROQ_API_KEY)
15
 
16
- HF_API_KEY = os.getenv("HF_API_KEY")
17
-
18
- if not HF_API_KEY:
19
- raise ValueError(
20
- "API Key Hugging Face tidak ditemukan. Pastikan file .env berisi HF_API_KEY."
21
- )
22
-
23
- # Inisialisasi klien API Hugging Face
24
- huggingface_client = InferenceClient(api_key=HF_API_KEY)
25
-
26
- # Load Faster Whisper model versi large
27
- model = faster_whisper.WhisperModel("turbo", device="cpu", compute_type="int8")
28
-
29
 
30
  def chat_with_groq(message):
31
  """Handles conversation with Groq LLM."""
@@ -51,20 +38,22 @@ def save_to_file(content, filename):
51
  return filename
52
 
53
 
54
- def transcribe_audio(audio_path):
55
  """Transkripsi audio menggunakan Faster Whisper tanpa koreksi model Hugging Face."""
56
- # segments, _ = model.transcribe(audio_path)
57
  # raw_transcription = " ".join(segment.text for segment in segments)
58
- raw_transcription = gclient.audio.transcriptions.create(
59
- file=(audio_path, audio_path.read()),
60
- model="whisper-large-v3-turbo",
61
- language="id",
62
- )
63
- print(raw_transcription)
 
 
64
  return (
65
  raw_transcription,
66
  save_to_file(raw_transcription, "transcription_large.txt"),
67
- audio_path,
68
  )
69
 
70
 
@@ -82,13 +71,7 @@ def generate_soap_summary(transcription_text, selected_model):
82
 
83
  ### Catatan SOAP:
84
  """
85
- # messages = [
86
- # {"role": "user", "content": template.format(dialogue=transcription_text)}
87
- # ]
88
- # response = huggingface_client.chat.completions.create(
89
- # model=selected_model, messages=messages, max_tokens=1000, stream=False
90
- # )
91
- # soap = response.choices[0].message.content.strip()
92
  soap = chat_with_groq(template.format(dialogue=transcription_text))
93
  return soap, save_to_file(soap, "soap_summary.txt")
94
 
@@ -105,13 +88,6 @@ def detect_medical_tags(transcription_text, selected_model):
105
  ### Percakapan:
106
  {dialogue}
107
  """
108
- # messages = [
109
- # {"role": "user", "content": template.format(dialogue=transcription_text)}
110
- # ]
111
- # response = huggingface_client.chat.completions.create(
112
- # model=selected_model, messages=messages, max_tokens=500, stream=False
113
- # )
114
- # tags = response.choices[0].message.content.strip()
115
  tags = chat_with_groq(template.format(dialogue=transcription_text))
116
  return tags, save_to_file(tags, "medical_tags.txt")
117
 
 
13
  raise ValueError("GROQ API NOT FOUND!")
14
  gclient = Groq(api_key=GROQ_API_KEY)
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  def chat_with_groq(message):
18
  """Handles conversation with Groq LLM."""
 
38
  return filename
39
 
40
 
41
+ def transcribe_audio(audio_file):
42
  """Transkripsi audio menggunakan Faster Whisper tanpa koreksi model Hugging Face."""
43
+ # segments, _ = model.transcribe(audio_file)
44
  # raw_transcription = " ".join(segment.text for segment in segments)
45
+ with open(audio_file, "rb") as file:
46
+ res = gclient.audio.transcriptions.create(
47
+ file=(audio_file, audio_file.read()),
48
+ model="whisper-large-v3-turbo",
49
+ language="id",
50
+ )
51
+ print(res)
52
+ raw_transcription = res.text
53
  return (
54
  raw_transcription,
55
  save_to_file(raw_transcription, "transcription_large.txt"),
56
+ audio_file,
57
  )
58
 
59
 
 
71
 
72
  ### Catatan SOAP:
73
  """
74
+
 
 
 
 
 
 
75
  soap = chat_with_groq(template.format(dialogue=transcription_text))
76
  return soap, save_to_file(soap, "soap_summary.txt")
77
 
 
88
  ### Percakapan:
89
  {dialogue}
90
  """
 
 
 
 
 
 
 
91
  tags = chat_with_groq(template.format(dialogue=transcription_text))
92
  return tags, save_to_file(tags, "medical_tags.txt")
93