From ac350d19b076da80ab7c3602c9687ce5b36c5b5b Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 10 May 2024 22:42:40 -0700 Subject: [PATCH] API Selection working --- .gitignore | Bin 6972 -> 6986 bytes .idea/.gitignore | 8 +++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 7 +++ .idea/modules.xml | 8 +++ .idea/tldw.iml | 14 +++++ .idea/vcs.xml | 6 ++ HF/app.py | 8 +-- config.txt | 2 +- req.txt | Bin 0 -> 3960 bytes requirements.txt | 19 +++++-- summarize.py | 52 ++++++++++-------- 12 files changed, 96 insertions(+), 34 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/tldw.iml create mode 100644 .idea/vcs.xml create mode 100644 req.txt diff --git a/.gitignore b/.gitignore index c8170aff1c3b56f157024405d0a470fb0f10d8df..5f0864c2e97baada722e11795a64128e5f1f90ca 100644 GIT binary patch delta 22 YcmdmEcFJsnjWnOWUS>*aA{Ueb09h0U`~Uy| delta 7 OcmX?Qw#RIPjWhra_yYO> diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..dce6d35 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..95309e3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/tldw.iml b/.idea/tldw.iml new file mode 100644 index 0000000..8e5446a --- /dev/null +++ b/.idea/tldw.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HF/app.py b/HF/app.py index b9076b4..e283059 100644 --- a/HF/app.py +++ b/HF/app.py @@ -1282,10 +1282,9 @@ def launch_ui(demo_mode=False): iface = gr.Interface( # fn=lambda url, num_speakers, whisper_model, offset, api_name, api_key: process_url(url, num_speakers, whisper_model, offset, api_name=api_name, api_key=api_key, demo_mode=demo_mode), +# fn=lambda url, num_speakers, whisper_model, offset, api_name, custom_prompt, api_key: process_url(url, num_speakers, whisper_model, offset, api_name, api_key, demo_mode=demo_mode), + fn=lambda *args: process_url(*args, demo_mode=demo_mode), - fn=lambda url, num_speakers, whisper_model, offset, api_name, api_key: process_url(url, num_speakers, whisper_model, offset, api_name, api_key, demo_mode=demo_mode), - -# fn=lambda *args: process_url(*args, demo_mode=demo_mode), inputs=inputs, outputs=[ gr.components.Textbox(label="Transcription", value=lambda: "", max_lines=10), @@ -1532,7 +1531,8 @@ if __name__ == "__main__": launch_ui(demo_mode=args.demo_mode) try: - results = main(args.input_path, api_name=args.api_name, api_key=args.api_key, num_speakers=args.num_speakers, whisper_model=args.whisper_model, offset=args.offset, vad_filter=args.vad_filter, download_video_flag=args.video) + results = main(input_path, api_name=api_name, api_key=api_key, num_speakers=num_speakers, whisper_model="small.en", offset=offset, vad_filter=vad_filter, download_video_flag=download_video_flag) + results = main(args.input_path, api_name=args.api_name, api_key=args.api_key, num_speakers=args.num_speakers, whisper_model="small.en", offset=args.offset, vad_filter=args.vad_filter, download_video_flag=args.video) logging.info('Transcription process completed.') except Exception as e: logging.error('An error occurred during the transcription process.') diff --git a/config.txt b/config.txt index a90803a..efcff71 100644 --- a/config.txt +++ b/config.txt @@ -1,5 +1,5 @@ [API] -anthropic_api_key = cohere_model = command-r-plus diff --git a/req.txt b/req.txt new file mode 100644 index 0000000000000000000000000000000000000000..123f3a509958e850a1d518543268ebe0d707893b GIT binary patch literal 3960 zcmZ{nOK%%T5QOI(AU}nIcPY!xA&2A`#6WBBq}z0U3xa~5$p4Q497d*cCX_^yY_n*zspy90CCI^o)vv*I1Z zZq`W!=>u~!`JEKYy=cRajAOqSA+|0OQ!}zJA_6&jaYA0aI8P6qYZ(=xnfvlQaI}b= z)SLe913ax{J1O2w*xe)7mYw|8XA&5zFaFbDEo0HuNx2B)MzK+wGp9C;bfw(8u&x6a z*4rVDE#}hkQw=!}^d!4W*PG~lo@XBFR8@tq2L2z^E%JjbCoA>ds>80@ou#+v#eR6b zSGH96N}s#N`M_=}*rKv6ZQ#mPQH~x)2@8n6yppYF)$k{3bfZ6wH+Y{mzwxt%tr+ec*A% zx(}Y@bI~`IZZ*y0IkFB>7u+7T=N9t1DB?sX*ps=7h*~-RGN(pfCmqCJW{(jUt8qH}S(cgfg;vsjJ5pgM zORs8C#Z$3TIqyBxh2pY)W3o1g4(pxH9OZ>V(3d&DvxzK@L-g!tR^J4dwjYF%9RyO( z175zrtOh(#J3H1k?|XB^#@zv=(3U@wn&p%*Y%3Y(n(uec#%LcFP!=5`%ukm45uzh(Cpqpv%gda0hvE-dP2@cpCV_vDv z8~a94_sZE16HkuuSvrPp^F`$8`(B>6H=wr&m@0oY@=kbo?QMpt`>4a+16$VH>rG^> zu$kT1s!JoG$USEWm-8}B# zG`i#I;5J~JlEwFTRT^)ph0fMJW~_e6Q7iKcgNc!DdM;1uH?_DAY|p&qiGiQ_SL2tvPD*|gX9?OiCTGJ1*|g-u}AdGGE9 zR@lh7Z^32OJuU8_Gj+1TM!qrda93<+pR%c81zr;EG^RWGcu`*T?2c3=_S!(c-Rm~@ z%haq8kvBQpz%Oeezyxfk51ZC?(Fdlf8Q$CQ^Q0J5;TOGU-aUr_BgAi~4BU)W|JO+T zTJsF}JUFa!&huih=J*_r5?|V8QdWJf{h!yfFpQPrTqroPeo++H3k!F#wbPdW53B+a zJ2^FK9m9^*od2=;4P7f5TdkXWMfn=tOTVRZFu&ZgDA#^jNixL# RWovJxUE|5kM@8O@{{h?yIY|Hj literal 0 HcmV?d00001 diff --git a/requirements.txt b/requirements.txt index 9b0c34b..3ae9a87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,8 +26,10 @@ fire==0.6.0 flatbuffers==24.3.25 fonttools==4.51.0 fsspec==2024.3.1 -gradio==4.29.0 -gradio_client==0.16.1 +gradio +#gradio==4.29.0 +gradio_client +#gradio_client==0.16.1 h11==0.14.0 httpcore==1.0.5 httptools==0.6.1 @@ -89,8 +91,6 @@ timm==0.9.16 tokenizers==0.15.2 tomlkit==0.12.0 toolz==0.12.1 -torch==2.2.2+cu121 -torchaudio==2.2.2+cu121 torchvision==0.17.2 tqdm==4.66.2 transformers==4.39.3 @@ -101,5 +101,12 @@ ujson==5.9.0 urllib3==2.2.1 uvicorn==0.29.0 watchfiles==0.21.0 -websockets==11.0.3 -yt-dlp==2024.4.9 +websockets +#websockets==11.0.3 +yt-dlp +#yt-dlp==2024.4.9 +--extra-index-url https://download.pytorch.org/whl/cu113 +torch +torchaudio +#torch==2.2.2+cu121 +#torchaudio==2.2.2+cu121 \ No newline at end of file diff --git a/summarize.py b/summarize.py index c6bbca4..9953d77 100644 --- a/summarize.py +++ b/summarize.py @@ -341,6 +341,7 @@ def process_local_file(file_path): # def process_url(input_path, num_speakers=2, whisper_model="small.en", custom_prompt=None, offset=0, api_name=None, api_key=None, vad_filter=False, download_video_flag=False, demo_mode=False): + custom_prompt = "" if demo_mode: # api_name = "" # api_key = "" @@ -766,7 +767,7 @@ def extract_text_from_segments(segments): -def summarize_with_openai(api_key, file_path, model): +def summarize_with_openai(api_key, file_path, model, custom_prompt): try: logging.debug("openai: Loading json data for summarization") with open(file_path, 'r') as file: @@ -779,7 +780,12 @@ def summarize_with_openai(api_key, file_path, model): 'Authorization': f'Bearer {api_key}', 'Content-Type': 'application/json' } - +# headers = { +# 'Authorization': f'Bearer {api_key}', +# 'Content-Type': 'application/json' +# } + + logging.debug(f"openai: API Key is: {api_key}") logging.debug("openai: Preparing data + prompt for submittal") openai_prompt = f"{text} \n\n\n\n{custom_prompt}" data = { @@ -816,7 +822,7 @@ def summarize_with_openai(api_key, file_path, model): -def summarize_with_claude(api_key, file_path, model): +def summarize_with_claude(api_key, file_path, model, custom_prompt): try: logging.debug("anthropic: Loading JSON data") with open(file_path, 'r') as file: @@ -886,7 +892,7 @@ def summarize_with_claude(api_key, file_path, model): # Summarize with Cohere -def summarize_with_cohere(api_key, file_path, model): +def summarize_with_cohere(api_key, file_path, model, custom_prompt): try: logging.basicConfig(level=logging.DEBUG) logging.debug("cohere: Loading JSON data") @@ -930,7 +936,7 @@ def summarize_with_cohere(api_key, file_path, model): logging.error("Expected data not found in API response.") return "Expected data not found in API response." else: - logging.error(f"cohere: API request failed with status code {response.status_code}: {resposne.text}") + logging.error(f"cohere: API request failed with status code {response.status_code}: {response.text}") print(f"Failed to process summary, status code {response.status_code}: {response.text}") return f"cohere: API request failed: {response.text}" @@ -941,7 +947,7 @@ def summarize_with_cohere(api_key, file_path, model): # https://console.groq.com/docs/quickstart -def summarize_with_groq(api_key, file_path, model): +def summarize_with_groq(api_key, file_path, model, custom_prompt): try: logging.debug("groq: Loading JSON data") with open(file_path, 'r') as file: @@ -997,7 +1003,7 @@ def summarize_with_groq(api_key, file_path, model): # # Local Summarization -def summarize_with_llama(api_url, file_path, token): +def summarize_with_llama(api_url, file_path, token, custom_prompt): try: logging.debug("llama: Loading JSON data") with open(file_path, 'r') as file: @@ -1045,7 +1051,7 @@ def summarize_with_llama(api_url, file_path, token): # https://lite.koboldai.net/koboldcpp_api#/api%2Fv1/post_api_v1_generate -def summarize_with_kobold(api_url, file_path): +def summarize_with_kobold(api_url, file_path,custom_prompt): try: logging.debug("kobold: Loading JSON data") with open(file_path, 'r') as file: @@ -1096,7 +1102,7 @@ def summarize_with_kobold(api_url, file_path): # https://github.com/oobabooga/text-generation-webui/wiki/12-%E2%80%90-OpenAI-API -def summarize_with_oobabooga(api_url, file_path): +def summarize_with_oobabooga(api_url, file_path, custom_prompt): try: logging.debug("ooba: Loading JSON data") with open(file_path, 'r') as file: @@ -1336,61 +1342,61 @@ def main(input_path, api_name=None, api_key=None, num_speakers=2, whisper_model= api_key = openai_api_key try: logging.debug(f"MAIN: trying to summarize with openAI") - summary = summarize_with_openai(api_key, json_file_path, openai_model) + summary = summarize_with_openai(api_key, json_file_path, openai_model, custom_prompt) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " + requests.status_code = "Connection: " elif api_name.lower() == "anthropic": api_key = anthropic_api_key try: logging.debug(f"MAIN: Trying to summarize with anthropic") - summary = summarize_with_claude(api_key, json_file_path, anthropic_model) + summary = summarize_with_claude(api_key, json_file_path, anthropic_model, custom_prompt) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " + requests.status_code = "Connection: " elif api_name.lower() == "cohere": api_key = cohere_api_key try: logging.debug(f"MAIN: Trying to summarize with cohere") summary = summarize_with_cohere(api_key, json_file_path, cohere_model) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " + requests.status_code = "Connection: " elif api_name.lower() == "groq": api_key = groq_api_key try: logging.debug(f"MAIN: Trying to summarize with Groq") summary = summarize_with_groq(api_key, json_file_path, groq_model) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " + requests.status_code = "Connection: " elif api_name.lower() == "llama": token = llama_api_key llama_ip = llama_api_IP try: logging.debug(f"MAIN: Trying to summarize with Llama.cpp") - summary = summarize_with_llama(llama_ip, json_file_path, token) + summary = summarize_with_llama(llama_ip, json_file_path, token, custom_prompt) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " + requests.status_code = "Connection: " elif api_name.lower() == "kobold": token = kobold_api_key kobold_ip = kobold_api_IP try: logging.debug(f"MAIN: Trying to summarize with kobold.cpp") - summary = summarize_with_kobold(kobold_ip, json_file_path) + summary = summarize_with_kobold(kobold_ip, json_file_path, custom_prompt) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " + requests.status_code = "Connection: " elif api_name.lower() == "ooba": token = ooba_api_key ooba_ip = ooba_api_IP try: logging.debug(f"MAIN: Trying to summarize with oobabooga") - summary = summarize_with_oobabooga(ooba_ip, json_file_path) + summary = summarize_with_oobabooga(ooba_ip, json_file_path, custom_prompt) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " - if api_name.lower() == "huggingface": + requests.status_code = "Connection: " + elif api_name.lower() == "huggingface": api_key = huggingface_api_key try: logging.debug(f"MAIN: Trying to summarize with huggingface") summarize_with_huggingface(api_key, json_file_path) except requests.exceptions.ConnectionError: - r.status_code = "Connection: " + requests.status_code = "Connection: " else: logging.warning(f"Unsupported API: {api_name}")