Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,8 +48,7 @@ LOGGER.setLevel(log_level)
|
|
48 |
|
49 |
class DemandForecasting:
|
50 |
def __init__(self):
|
51 |
-
self.client =
|
52 |
-
self.whisper_model = whisper.load_model("medium.en")
|
53 |
|
54 |
|
55 |
def get_column(self,train_csv_path: str):
|
@@ -319,44 +318,46 @@ class DemandForecasting:
|
|
319 |
return None
|
320 |
|
321 |
def audio_to_text(self, audio_path):
|
322 |
-
""
|
323 |
-
|
324 |
-
""
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
print("audio_to_text",result["text"])
|
329 |
-
return result["text"]
|
330 |
|
331 |
|
332 |
def parse_text(self, text, column_list):
|
333 |
|
334 |
# Define the prompt or input for the model
|
335 |
conversation =[{"role": "system", "content": ""},
|
336 |
-
{"role": "user", "content":f"""
|
337 |
-
l values should be intiger data type. if date in there the format is dd-mm-YYYY.
|
338 |
text```{text}```
|
|
|
|
|
339 |
return result should be in JSON format:
|
340 |
-
|
341 |
"""
|
342 |
-
}]
|
343 |
|
344 |
# Generate a response from the GPT-3 model
|
345 |
chat_completion = self.client.chat.completions.create(
|
346 |
-
model = "
|
347 |
messages = conversation,
|
348 |
max_tokens=500,
|
349 |
temperature=0,
|
350 |
n=1,
|
351 |
stop=None,
|
|
|
352 |
)
|
353 |
|
354 |
# Extract the generated text from the API response
|
355 |
generated_text = chat_completion.choices[0].message.content
|
356 |
-
|
357 |
-
# Assuming jsonString is your JSON string
|
358 |
-
|
359 |
-
|
|
|
|
|
|
|
360 |
return json_data
|
361 |
|
362 |
def main(self, train_csv_path: str, audio_path, target_column, column_list) -> None:
|
|
|
48 |
|
49 |
class DemandForecasting:
|
50 |
def __init__(self):
|
51 |
+
self.client = OpenAI()
|
|
|
52 |
|
53 |
|
54 |
def get_column(self,train_csv_path: str):
|
|
|
318 |
return None
|
319 |
|
320 |
def audio_to_text(self, audio_path):
|
321 |
+
audio_file= open(audio_path, "rb")
|
322 |
+
transcription = self.client.audio.transcriptions.create(
|
323 |
+
model="whisper-1",
|
324 |
+
file=audio_file)
|
325 |
+
print(transcription.text)
|
326 |
+
return transcription.text
|
|
|
|
|
327 |
|
328 |
|
329 |
def parse_text(self, text, column_list):
|
330 |
|
331 |
# Define the prompt or input for the model
|
332 |
conversation =[{"role": "system", "content": ""},
|
333 |
+
{"role": "user", "content":f""" Extract the values for this given column list:{column_list}, from the given text. all values should be integer data type. if date in given text, the date format should be in dd-mm-YYYY.
|
|
|
334 |
text```{text}```
|
335 |
+
the text may contains other name key and values, use consine similarity to map with column list.
|
336 |
+
the column names should be keys.
|
337 |
return result should be in JSON format:
|
|
|
338 |
"""
|
339 |
+
}]
|
340 |
|
341 |
# Generate a response from the GPT-3 model
|
342 |
chat_completion = self.client.chat.completions.create(
|
343 |
+
model = "gpt-3.5-turbo",
|
344 |
messages = conversation,
|
345 |
max_tokens=500,
|
346 |
temperature=0,
|
347 |
n=1,
|
348 |
stop=None,
|
349 |
+
response_format={ "type": "json_object" },
|
350 |
)
|
351 |
|
352 |
# Extract the generated text from the API response
|
353 |
generated_text = chat_completion.choices[0].message.content
|
354 |
+
print(generated_text)
|
355 |
+
# # Assuming jsonString is your JSON string
|
356 |
+
try:
|
357 |
+
json_data = json.loads(generated_text)
|
358 |
+
except Exception as e:
|
359 |
+
return e
|
360 |
+
# print("parse_text",json_data)
|
361 |
return json_data
|
362 |
|
363 |
def main(self, train_csv_path: str, audio_path, target_column, column_list) -> None:
|