Spaces:
Runtime error
Runtime error
Commit
·
8b150b6
1
Parent(s):
add931b
testing lftk
Browse files
app.py
CHANGED
|
@@ -14,6 +14,27 @@ vicuna_model = AutoModelForCausalLM.from_pretrained("lmsys/vicuna-7b-v1.3")
|
|
| 14 |
llama_tokenizer = AutoTokenizer.from_pretrained("daryl149/llama-2-7b-chat-hf")
|
| 15 |
llama_model = AutoModelForCausalLM.from_pretrained("daryl149/llama-2-7b-chat-hf")
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def update_api_key(new_key):
|
| 18 |
print("update_api_key ran")
|
| 19 |
global api_key
|
|
@@ -225,7 +246,7 @@ def interface():
|
|
| 225 |
# Outputs
|
| 226 |
|
| 227 |
user_prompt_1 = gr.Textbox(label="Original prompt")
|
| 228 |
-
|
| 229 |
|
| 230 |
with gr.Row():
|
| 231 |
gpt_ling_ents_chatbot = gr.Chatbot(label="gpt-3.5")
|
|
@@ -242,6 +263,11 @@ def interface():
|
|
| 242 |
|
| 243 |
ling_ents_btn.click(fn=update_textbox, inputs=ling_ents_prompt, outputs=user_prompt_1, api_name="ling_ents_btn")
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
# Event Handler for GPT 3.5 Chatbot
|
| 246 |
ling_ents_btn.click(gpt_respond, inputs=[have_key2, linguistic_entities, ling_ents_prompt, gpt_ling_ents_chatbot],
|
| 247 |
outputs=[ling_ents_prompt, gpt_ling_ents_chatbot])
|
|
|
|
| 14 |
llama_tokenizer = AutoTokenizer.from_pretrained("daryl149/llama-2-7b-chat-hf")
|
| 15 |
llama_model = AutoModelForCausalLM.from_pretrained("daryl149/llama-2-7b-chat-hf")
|
| 16 |
|
| 17 |
+
def linguistic_features(message):
|
| 18 |
+
# Load a trained spaCy pipeline
|
| 19 |
+
nlp = spacy.load("en_core_web_sm")
|
| 20 |
+
|
| 21 |
+
# Create a spaCy doc object
|
| 22 |
+
doc = nlp(message)
|
| 23 |
+
|
| 24 |
+
# Initiate LFTK extractor by passing in the doc
|
| 25 |
+
LFTK_extractor = lftk.Extractor(docs=doc)
|
| 26 |
+
|
| 27 |
+
# Customize LFTK extractor (optional)
|
| 28 |
+
LFTK_extractor.customize(stop_words=True, punctuations=False, round_decimal=3)
|
| 29 |
+
|
| 30 |
+
# Use LFTK to dynamically extract handcrafted linguistic features
|
| 31 |
+
features_to_extract = lftk.search_features(family="wordsent", language="general", return_format="list_key")
|
| 32 |
+
extracted_features = LFTK_extractor.extract(features=features_to_extract)
|
| 33 |
+
|
| 34 |
+
print('Linguistic Features:', extracted_features)
|
| 35 |
+
|
| 36 |
+
return extracted_features
|
| 37 |
+
|
| 38 |
def update_api_key(new_key):
|
| 39 |
print("update_api_key ran")
|
| 40 |
global api_key
|
|
|
|
| 246 |
# Outputs
|
| 247 |
|
| 248 |
user_prompt_1 = gr.Textbox(label="Original prompt")
|
| 249 |
+
linguistic_features_textbox = gr.Textbox(label="Linguistic Features", disabled=True)
|
| 250 |
|
| 251 |
with gr.Row():
|
| 252 |
gpt_ling_ents_chatbot = gr.Chatbot(label="gpt-3.5")
|
|
|
|
| 263 |
|
| 264 |
ling_ents_btn.click(fn=update_textbox, inputs=ling_ents_prompt, outputs=user_prompt_1, api_name="ling_ents_btn")
|
| 265 |
|
| 266 |
+
ling_ents_btn.click(lambda _,
|
| 267 |
+
message=ling_ents_prompt: linguistic_features_textbox.update(linguistic_features(ling_ents_prompt.value)),
|
| 268 |
+
inputs=[ling_ents_prompt],
|
| 269 |
+
outputs=[linguistic_features_textbox])
|
| 270 |
+
|
| 271 |
# Event Handler for GPT 3.5 Chatbot
|
| 272 |
ling_ents_btn.click(gpt_respond, inputs=[have_key2, linguistic_entities, ling_ents_prompt, gpt_ling_ents_chatbot],
|
| 273 |
outputs=[ling_ents_prompt, gpt_ling_ents_chatbot])
|