Kim Adams commited on
Commit ·
4e93024
1
Parent(s): a3d8390
changing to translation
Browse files- app.py +7 -7
- setup.sh +0 -2
- summarization/__pycache__/summarization.cpython-311.pyc +0 -0
- summarization/__pycache__/ui_summarize.cpython-311.pyc +0 -0
- summarization/summarization.py +9 -3
- summarization/ui_summarize.py +17 -4
- utilities/__pycache__/constants.cpython-311.pyc +0 -0
- utilities/__pycache__/prompt_constants.cpython-311.pyc +0 -0
- utilities/constants.py +7 -0
- utilities/data/csv/policy.csv +8 -3
- utilities/data/pkl/policy.pkl +2 -2
- utilities/prompt_constants.py +2 -1
app.py
CHANGED
|
@@ -4,10 +4,10 @@ import openai
|
|
| 4 |
from ui.app_theme import SoftBlue
|
| 5 |
from utilities import constants,api_keys
|
| 6 |
from prompts import ui_prompt_builder
|
| 7 |
-
from chat_bot import ui_simple_chat
|
| 8 |
-
|
| 9 |
-
from image_gen import ui_image_generation
|
| 10 |
from summarization import ui_summarize
|
|
|
|
| 11 |
from recording_analysis import ui_recording_analysis
|
| 12 |
from slack_sentiment_analysis import ui_sentiment_analysis
|
| 13 |
from image_to_text import image_to_text_translator as ui_image_to_text
|
|
@@ -16,16 +16,16 @@ from text_analysis import ui_text_analysis'''
|
|
| 16 |
openai.api_key = api_keys.APIKeys().get_key('OPENAI_API_KEY')
|
| 17 |
|
| 18 |
prompt_builder=ui_prompt_builder.ui
|
| 19 |
-
usaa_advisor=ui_simple_chat.ui
|
| 20 |
-
|
| 21 |
summarize=ui_summarize.ui
|
| 22 |
-
image_generator=ui_image_generation.ui
|
| 23 |
video_analysis=ui_recording_analysis.ui
|
| 24 |
slack_sentiment=ui_sentiment_analysis.ui
|
| 25 |
#git_advisor=ui_simple_chat_git.ui
|
| 26 |
#image_to_text=ui_image_to_text.ui
|
| 27 |
#text_analysis=ui_text_analysis.ui'''
|
| 28 |
|
| 29 |
-
ui = gr.TabbedInterface([prompt_builder,
|
| 30 |
|
| 31 |
ui.launch()
|
|
|
|
| 4 |
from ui.app_theme import SoftBlue
|
| 5 |
from utilities import constants,api_keys
|
| 6 |
from prompts import ui_prompt_builder
|
| 7 |
+
#from chat_bot import ui_simple_chat
|
| 8 |
+
#from image_gen import ui_image_generation
|
|
|
|
| 9 |
from summarization import ui_summarize
|
| 10 |
+
''' Disabled#
|
| 11 |
from recording_analysis import ui_recording_analysis
|
| 12 |
from slack_sentiment_analysis import ui_sentiment_analysis
|
| 13 |
from image_to_text import image_to_text_translator as ui_image_to_text
|
|
|
|
| 16 |
openai.api_key = api_keys.APIKeys().get_key('OPENAI_API_KEY')
|
| 17 |
|
| 18 |
prompt_builder=ui_prompt_builder.ui
|
| 19 |
+
###usaa_advisor=ui_simple_chat.ui
|
| 20 |
+
|
| 21 |
summarize=ui_summarize.ui
|
| 22 |
+
'''image_generator=ui_image_generation.ui
|
| 23 |
video_analysis=ui_recording_analysis.ui
|
| 24 |
slack_sentiment=ui_sentiment_analysis.ui
|
| 25 |
#git_advisor=ui_simple_chat_git.ui
|
| 26 |
#image_to_text=ui_image_to_text.ui
|
| 27 |
#text_analysis=ui_text_analysis.ui'''
|
| 28 |
|
| 29 |
+
ui = gr.TabbedInterface([prompt_builder, summarize], (constants.UI_1, "Summarize"),theme=SoftBlue())
|
| 30 |
|
| 31 |
ui.launch()
|
setup.sh
CHANGED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
# Install SpaCy modeldock
|
| 2 |
-
python -m spacy download en_core_web_sm
|
|
|
|
|
|
|
|
|
summarization/__pycache__/summarization.cpython-311.pyc
CHANGED
|
Binary files a/summarization/__pycache__/summarization.cpython-311.pyc and b/summarization/__pycache__/summarization.cpython-311.pyc differ
|
|
|
summarization/__pycache__/ui_summarize.cpython-311.pyc
CHANGED
|
Binary files a/summarization/__pycache__/ui_summarize.cpython-311.pyc and b/summarization/__pycache__/ui_summarize.cpython-311.pyc differ
|
|
|
summarization/summarization.py
CHANGED
|
@@ -7,15 +7,21 @@ def Completion(summary_messages):
|
|
| 7 |
messages=summary_messages)
|
| 8 |
return response["choices"][0]["message"]["content"]
|
| 9 |
|
| 10 |
-
def SummarizeCompletion(code):
|
| 11 |
truncated_prefix=""
|
| 12 |
if len(code) > 14000:
|
| 13 |
truncated_prefix=constants.SUMMARIZATION_TRUNCATION
|
| 14 |
truncated_code = code[:14000]
|
| 15 |
|
| 16 |
summary_messages = []
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
response_message = Completion(summary_messages)
|
| 21 |
summary_messages.append({"role": "assistant", "content": response_message})
|
|
|
|
| 7 |
messages=summary_messages)
|
| 8 |
return response["choices"][0]["message"]["content"]
|
| 9 |
|
| 10 |
+
def SummarizeCompletion(code, sample):
|
| 11 |
truncated_prefix=""
|
| 12 |
if len(code) > 14000:
|
| 13 |
truncated_prefix=constants.SUMMARIZATION_TRUNCATION
|
| 14 |
truncated_code = code[:14000]
|
| 15 |
|
| 16 |
summary_messages = []
|
| 17 |
+
if(sample!=""):
|
| 18 |
+
summary_messages.append({"role": "system", "content": prompt_constants.TRANSLATION_PROMPT_PREFIX+sample+prompt_constants.TRANSLATION_PROMPT_SUFFIX})
|
| 19 |
+
summary_messages.append({"role": "user", "content": truncated_code})
|
| 20 |
+
print("Sample not '': ",sample, " summary_messages: ",summary_messages)
|
| 21 |
+
else:
|
| 22 |
+
summary_messages.append({"role": "system", "content": prompt_constants.SUMMARY_PROMPT})
|
| 23 |
+
summary_messages.append({"role": "user", "content": truncated_code})
|
| 24 |
+
print("Sample: ",sample, " summary_messages: ",summary_messages)
|
| 25 |
|
| 26 |
response_message = Completion(summary_messages)
|
| 27 |
summary_messages.append({"role": "assistant", "content": response_message})
|
summarization/ui_summarize.py
CHANGED
|
@@ -2,12 +2,16 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
|
|
|
|
|
|
| 5 |
from utilities import constants
|
| 6 |
from summarization import summarization
|
| 7 |
from translators import translate_pdf_to_text
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
df = pd.DataFrame(sum_messages)
|
| 12 |
return sum_text,df
|
| 13 |
|
|
@@ -15,6 +19,11 @@ def InitDF():
|
|
| 15 |
global summaryDF
|
| 16 |
summaryDF=pd.DataFrame({"role": [""], "content": [""] })
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def UpdateWithExample(newExample):
|
| 19 |
fileName=newExample.replace(" ","_").lower()
|
| 20 |
if os.path.exists(f"{constants.TXT_PREFIX}{fileName}.txt"):
|
|
@@ -43,12 +52,16 @@ with gr.Blocks() as ui:
|
|
| 43 |
examples = gr.Radio([constants.EX_1, constants.EX_2, constants.EX_3, constants.EX_4, constants.EX_5,
|
| 44 |
constants.EX_6, constants.EX_7, constants.EX_8, constants.EX_9, constants.EX_10],
|
| 45 |
show_label=False, info=constants.SUMMARIZE_INFO)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
with gr.Row():
|
| 47 |
summarize=gr.Button(value=constants.SUMMARIZE, variant="primary")
|
| 48 |
with gr.Row():
|
| 49 |
summaryDF=gr.DataFrame(type="pandas", value=pd.DataFrame({"role": [""], "content": [""] }),
|
| 50 |
wrap=True, show_label=False, label=constants.OPENAI_LOG)
|
| 51 |
-
summarize.click(Summary, inputs=[code], outputs=[summary,summaryDF])
|
| 52 |
examples.input(UpdateWithExample,inputs=[examples], outputs=[code])
|
| 53 |
-
|
| 54 |
InitDF()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import os
|
| 5 |
+
|
| 6 |
+
from traitlets import default
|
| 7 |
from utilities import constants
|
| 8 |
from summarization import summarization
|
| 9 |
from translators import translate_pdf_to_text
|
| 10 |
|
| 11 |
+
sample=""
|
| 12 |
+
|
| 13 |
+
def Summary(code, samples):
|
| 14 |
+
sum_messages,sum_text = summarization.SummarizeCompletion(code,sample)
|
| 15 |
df = pd.DataFrame(sum_messages)
|
| 16 |
return sum_text,df
|
| 17 |
|
|
|
|
| 19 |
global summaryDF
|
| 20 |
summaryDF=pd.DataFrame({"role": [""], "content": [""] })
|
| 21 |
|
| 22 |
+
def UpdateWithSample(newSample):
|
| 23 |
+
global sample
|
| 24 |
+
sample=newSample
|
| 25 |
+
print("Sample: ",sample)
|
| 26 |
+
|
| 27 |
def UpdateWithExample(newExample):
|
| 28 |
fileName=newExample.replace(" ","_").lower()
|
| 29 |
if os.path.exists(f"{constants.TXT_PREFIX}{fileName}.txt"):
|
|
|
|
| 52 |
examples = gr.Radio([constants.EX_1, constants.EX_2, constants.EX_3, constants.EX_4, constants.EX_5,
|
| 53 |
constants.EX_6, constants.EX_7, constants.EX_8, constants.EX_9, constants.EX_10],
|
| 54 |
show_label=False, info=constants.SUMMARIZE_INFO)
|
| 55 |
+
gr.Markdown(constants.CODE_LANG_SAMPLES_MD)
|
| 56 |
+
with gr.Row():
|
| 57 |
+
samples = gr.Radio([constants.SAMPLE_1, constants.SAMPLE_2, constants.SAMPLE_3],
|
| 58 |
+
show_label=False, info=constants.TRANSLATION_INFO)
|
| 59 |
with gr.Row():
|
| 60 |
summarize=gr.Button(value=constants.SUMMARIZE, variant="primary")
|
| 61 |
with gr.Row():
|
| 62 |
summaryDF=gr.DataFrame(type="pandas", value=pd.DataFrame({"role": [""], "content": [""] }),
|
| 63 |
wrap=True, show_label=False, label=constants.OPENAI_LOG)
|
| 64 |
+
summarize.click(Summary, inputs=[code,samples], outputs=[summary,summaryDF])
|
| 65 |
examples.input(UpdateWithExample,inputs=[examples], outputs=[code])
|
| 66 |
+
samples.input(UpdateWithSample,inputs=[samples])
|
| 67 |
InitDF()
|
utilities/__pycache__/constants.cpython-311.pyc
CHANGED
|
Binary files a/utilities/__pycache__/constants.cpython-311.pyc and b/utilities/__pycache__/constants.cpython-311.pyc differ
|
|
|
utilities/__pycache__/prompt_constants.cpython-311.pyc
CHANGED
|
Binary files a/utilities/__pycache__/prompt_constants.cpython-311.pyc and b/utilities/__pycache__/prompt_constants.cpython-311.pyc differ
|
|
|
utilities/constants.py
CHANGED
|
@@ -39,6 +39,10 @@ VOICE_7="Serena"
|
|
| 39 |
VOICE_8="Sasha"
|
| 40 |
VOICE_9="Adam"
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
EX_1="Stored Procedure 1"
|
| 43 |
EX_2="Stored Procedure 2"
|
| 44 |
EX_3="COBOL 1"
|
|
@@ -150,7 +154,10 @@ NLP_POS_MAP_MD="### NLP POS Map"
|
|
| 150 |
FILE_DOES_NOT_EXIST="does not exist."
|
| 151 |
ORIGINAL_DOC="Original Document"
|
| 152 |
SUMMARIZE_INFO="Pick a document to summarize."
|
|
|
|
|
|
|
| 153 |
CODE_DOC_EXAMPLES_MD="### Code & Document Examples"
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
IMAGE_PROMPT="Image Prompt"
|
|
|
|
| 39 |
VOICE_8="Sasha"
|
| 40 |
VOICE_9="Adam"
|
| 41 |
|
| 42 |
+
SAMPLE_1="C#"
|
| 43 |
+
SAMPLE_2="Python"
|
| 44 |
+
SAMPLE_3="Java"
|
| 45 |
+
|
| 46 |
EX_1="Stored Procedure 1"
|
| 47 |
EX_2="Stored Procedure 2"
|
| 48 |
EX_3="COBOL 1"
|
|
|
|
| 154 |
FILE_DOES_NOT_EXIST="does not exist."
|
| 155 |
ORIGINAL_DOC="Original Document"
|
| 156 |
SUMMARIZE_INFO="Pick a document to summarize."
|
| 157 |
+
TRANSLATION_INFO="Pick a language to translate to."
|
| 158 |
+
|
| 159 |
CODE_DOC_EXAMPLES_MD="### Code & Document Examples"
|
| 160 |
+
CODE_LANG_SAMPLES_MD="### Target Language Options"
|
| 161 |
|
| 162 |
|
| 163 |
IMAGE_PROMPT="Image Prompt"
|
utilities/data/csv/policy.csv
CHANGED
|
@@ -16,10 +16,15 @@ Vehicles 2 Year: 2022
|
|
| 16 |
Vehicles 2 Vin: KNDCD3LD3N5536517
|
| 17 |
Vehicles 2 Body Type: Minivan
|
| 18 |
Vehicles 3 Make: Ford
|
| 19 |
-
Vehicles 3 Model:
|
| 20 |
Vehicles 3 Year: 2012
|
| 21 |
-
Vehicles 3 Vin:
|
| 22 |
-
Vehicles 3 Body Type:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
Coverages 0 Type: D
|
| 24 |
Coverages 0 Limits Of Liability: COMPREHENSIVE LOSS ACV LESS |D 200} 115.97D 200] 165.74D 200
|
| 25 |
Coverages 0 Deductible: None
|
|
|
|
| 16 |
Vehicles 2 Vin: KNDCD3LD3N5536517
|
| 17 |
Vehicles 2 Body Type: Minivan
|
| 18 |
Vehicles 3 Make: Ford
|
| 19 |
+
Vehicles 3 Model: Fusion
|
| 20 |
Vehicles 3 Year: 2012
|
| 21 |
+
Vehicles 3 Vin: 3FAHP0HA6CR069944
|
| 22 |
+
Vehicles 3 Body Type: Sedan
|
| 23 |
+
Vehicles 4 Make: JRIDE
|
| 24 |
+
Vehicles 4 Model: BHARE
|
| 25 |
+
Vehicles 4 Year: 2024
|
| 26 |
+
Vehicles 4 Vin: 09
|
| 27 |
+
Vehicles 4 Body Type: GAP PROTECTION
|
| 28 |
Coverages 0 Type: D
|
| 29 |
Coverages 0 Limits Of Liability: COMPREHENSIVE LOSS ACV LESS |D 200} 115.97D 200] 165.74D 200
|
| 30 |
Coverages 0 Deductible: None
|
utilities/data/pkl/policy.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e25b77148be86b5d2fedae6813fba3ed98d87d3ed27017251ac1352d0178269
|
| 3 |
+
size 513809
|
utilities/prompt_constants.py
CHANGED
|
@@ -15,7 +15,8 @@ ENGLISH_PROMPT="Provide responses entirely in English."
|
|
| 15 |
|
| 16 |
#summarization preset
|
| 17 |
SUMMARY_PROMPT="Identify the language (code) or genre (literature) as Type, summarize what this text does as simply as possible in the Summary. Identify key areas of interest in Key Concepts. Format response as follows:\nType: Python\nSummary: The code performs web scraping, text processing, tokenization, embedding generation, and question-answering tasks using OpenAI models and libraries.\nKey Concepts: Key concepts include the web scraping logic, text processing techniques, and the usage of OpenAI's embedding and question-answering models. Content: "
|
| 18 |
-
|
|
|
|
| 19 |
#sentiment/emotion presets
|
| 20 |
SENTIMENT_PROMPT="At the end of the response, Provide a sentiment evaluation of the user's input as \nSentiment: [Positive, Neutral, Negative]. Include '.' at the end of the sentence."
|
| 21 |
EMOTION_PROMPT = "At the end of the response, Provide an emotion evaluation of the user's input as \nEmotion: [Happy, Angry, Sad, etc]. Include '.' at the end of the sentence."
|
|
|
|
| 15 |
|
| 16 |
#summarization preset
|
| 17 |
SUMMARY_PROMPT="Identify the language (code) or genre (literature) as Type, summarize what this text does as simply as possible in the Summary. Identify key areas of interest in Key Concepts. Format response as follows:\nType: Python\nSummary: The code performs web scraping, text processing, tokenization, embedding generation, and question-answering tasks using OpenAI models and libraries.\nKey Concepts: Key concepts include the web scraping logic, text processing techniques, and the usage of OpenAI's embedding and question-answering models. Content: "
|
| 18 |
+
TRANSLATION_PROMPT_PREFIX="You will translate code from source language into "
|
| 19 |
+
TRANSLATION_PROMPT_SUFFIX=" language. Match data types, functions, and logic as closely as possible. Use comments to explain the code's purpose and functionality."
|
| 20 |
#sentiment/emotion presets
|
| 21 |
SENTIMENT_PROMPT="At the end of the response, Provide a sentiment evaluation of the user's input as \nSentiment: [Positive, Neutral, Negative]. Include '.' at the end of the sentence."
|
| 22 |
EMOTION_PROMPT = "At the end of the response, Provide an emotion evaluation of the user's input as \nEmotion: [Happy, Angry, Sad, etc]. Include '.' at the end of the sentence."
|