Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
enkaell committed Jun 22, 2023
1 parent ceac73e commit 8d28775
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@app.get('/', response_class=HTMLResponse)
def index(request: Request):
bots = []
bot_directories = [d for d in os.listdir(bots_dir) if os.path.isdir(os.path.join(bots_dir, d)) and d!= "gpt2tuned"]
bot_directories = [d for d in os.listdir(bots_dir) if os.path.isdir(os.path.join(bots_dir, d))]
for bot_dir in bot_directories:

# Dynamically load the bot's module
Expand Down
8 changes: 4 additions & 4 deletions bots/gpt2tuned/joke_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Bot:

def __init__(self):
# Loading models
self.pipeline1 = pipeline("text-classification", model='bert-base-uncased')
self.pipeline2 = pipeline("zero-shot-classification", model='bert-base-uncased')
self.pipe1 = pipeline("text-classification", model='bert-base-uncased')
self.pipe2 = pipeline("zero-shot-classification", model='bert-base-uncased')
# Final mark (0-10)
self.mark = 0

Expand All @@ -61,13 +61,13 @@ def tell_joke(self) -> str:
def rate_joke(self, joke) -> int:
self.mark = 0
print(joke)
result = self.pipeline1(joke)
result = self.pipe1(joke)
# Logical evaluation from bert-base-uncased on Regression
score = result[0]['score']
logic_score_1 = round(score*10)

# Logic evaluation based zero-shot classification with two parameters
result = self.pipeline2(joke, candidate_labels=["logical", "not logical"])['scores'][0]
result = self.pipe2(joke, candidate_labels=["logical", "not logical"])['scores'][0]
logic_score_2 = round(result*10)

# average count of words - https://insidegovuk.blog.gov.uk/2014/08/04/sentence-length-why-25-words-is-our-limit/
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"transformers>=4.0",
"textblob>=0.15.3",
"torch>=1.8.1",
"pytest>=6.2.2"
"pytest>=6.2.2",
"gpt-2-simple",
],

author="Konfuzio",
Expand Down

0 comments on commit 8d28775

Please sign in to comment.