-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed language selection and modularized code structure with issue #4
- Loading branch information
1 parent
19a8174
commit af2b19a
Showing
9 changed files
with
195 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
openai_api_key = os.getenv("OPENAI_KEY") | ||
model_id = os.getenv('MODEL_ID', 'large-v3') | ||
model_path = os.getenv('MODEL_PATH', 'whisper_model') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import openai | ||
from config import openai_api_key | ||
|
||
openai.api_key = openai_api_key | ||
|
||
def extract_entities(text): | ||
prompt = f""" | ||
The following entities are present in Indian Languages. | ||
Please extract the following entities from the text. | ||
Provide entities for both in English and the original language of the audio in well-structured format: | ||
Text: "{text}" | ||
- Name: | ||
- Phone Numbers: | ||
- Addresses: | ||
- Email: | ||
- PIN Code: | ||
- Occupation: | ||
- Gender: | ||
""" | ||
response = openai.chat.completions.create( | ||
model="gpt-3.5-turbo", | ||
messages=[ | ||
{"role": "system", "content": "You are a helpful assistant that extracts information from Indian multilingual text."}, | ||
{"role": "user", "content": prompt} | ||
], | ||
max_tokens=200 | ||
) | ||
entities_text = response.choices[0].message.content | ||
|
||
return entities_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import torch | ||
import whisper | ||
import numpy as np | ||
import streamlit as st | ||
|
||
@st.cache(allow_output_mutation=True) | ||
def load_model(model_id, model_path): | ||
device = "cuda" if torch.cuda.is_available() else "cpu" | ||
model = whisper.load_model(model_id, device=device, download_root=model_path) | ||
print( | ||
f"Model will be run on {device}\n" | ||
f"Model is {'multilingual' if model.is_multilingual else 'English-only'} " | ||
f"and has {sum(np.prod(p.shape) for p in model.parameters()):,} parameters." | ||
) | ||
return model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ openai-whisper | |
streamlit | ||
librosa | ||
pytest | ||
pytube |
Oops, something went wrong.