noequal commited on
Commit
9626dcf
·
1 Parent(s): 71a1ad1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -24
app.py CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
3
  import pandas as pd
4
  import torch
5
  from transformers import GPT2LMHeadModel, GPT2Tokenizer, GPT2ForSequenceClassification, TrainingArguments, Trainer, DataCollatorWithPadding, DataCollatorForLanguageModeling
 
6
 
7
  # Step 1: Set Up Your Environment
8
  # Environment setup and package installations.
@@ -45,29 +46,6 @@ if text:
45
  st.write('Classified Labels:')
46
  st.write(labels)
47
 
48
- # Function for generating text based on input
49
- def generate_text(input_text, model, tokenizer):
50
- # Append the special token to the input
51
- input_text = input_text + ' [LABEL]'
52
- input_ids = tokenizer.encode(input_text, return_tensors='pt')
53
- attention_mask = torch.ones_like(input_ids)
54
- outputs = model.generate(input_ids, attention_mask=attention_mask, max_length=len(input_ids) + 5, do_sample=True, top_p=0.95)
55
- generated = tokenizer.decode(outputs[0], skip_special_tokens=False)
56
- labels = generated.split(',')
57
- labels = [label.replace('[LABEL]', '').strip() for label in labels]
58
- return generated
59
-
60
- # Function for sequence classification
61
- def classify_text(input_text, model, tokenizer):
62
- # Tokenize the input text
63
- input_ids = tokenizer.encode(input_text, return_tensors='pt')
64
- attention_mask = torch.ones_like(input_ids)
65
- # Perform sequence classification
66
- result = model(input_ids, attention_mask=attention_mask)
67
- # Post-process the results (e.g., select labels based on a threshold)
68
- labels = post_process_labels(result)
69
- return labels
70
-
71
  # Post-process labels based on a threshold or confidence score
72
  def post_process_labels(results):
73
  # Implement your logic to extract and filter labels
@@ -76,4 +54,4 @@ def post_process_labels(results):
76
  # to determine whether it should be considered a valid theme.
77
  # Return the selected labels as a list.
78
  selected_labels = []
79
- return selected_labels
 
3
  import pandas as pd
4
  import torch
5
  from transformers import GPT2LMHeadModel, GPT2Tokenizer, GPT2ForSequenceClassification, TrainingArguments, Trainer, DataCollatorWithPadding, DataCollatorForLanguageModeling
6
+ from text_processor import generate_text, classify_text
7
 
8
  # Step 1: Set Up Your Environment
9
  # Environment setup and package installations.
 
46
  st.write('Classified Labels:')
47
  st.write(labels)
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  # Post-process labels based on a threshold or confidence score
50
  def post_process_labels(results):
51
  # Implement your logic to extract and filter labels
 
54
  # to determine whether it should be considered a valid theme.
55
  # Return the selected labels as a list.
56
  selected_labels = []
57
+ return selected_labels