Bofandra commited on
Commit
c8df060
1 Parent(s): fee6eca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -45,7 +45,7 @@ def respond(
45
  selected_references['similarity'] = scores.tolist()[0]
46
  sorted_references = selected_references.sort_values(by='similarity', ascending=False)
47
  print(sorted_references.shape[0])
48
- sorted_references = sorted_references.iloc[:1]
49
  sorted_references = sorted_references.sort_values(by='similarity', ascending=True)
50
  print(sorted_references.shape[0])
51
  print(sorted_references['similarity'].tolist())
@@ -54,17 +54,20 @@ def respond(
54
  translator = Translator()
55
 
56
  for index, row in sorted_references.iterrows():
57
- print(index)
58
- print(f'{row["user"]}')
59
- user = translator.translate(f'{row["user"]}', src='ar', dest='en').text
60
- print(user)
61
- #print(row['assistant'])
62
- assistant = translator.translate(row['assistant']).text
63
- #print(assistant)
64
- messages.append({"role": "user", "content":user })
65
- messages.append({"role": "assistant", "content": assistant})
 
 
 
 
66
 
67
-
68
  #adding more references
69
  df = pd.read_csv("moslem-bot-reference.csv")
70
  for index, row in df.iterrows():
 
45
  selected_references['similarity'] = scores.tolist()[0]
46
  sorted_references = selected_references.sort_values(by='similarity', ascending=False)
47
  print(sorted_references.shape[0])
48
+ sorted_references = sorted_references.iloc[:3]
49
  sorted_references = sorted_references.sort_values(by='similarity', ascending=True)
50
  print(sorted_references.shape[0])
51
  print(sorted_references['similarity'].tolist())
 
54
  translator = Translator()
55
 
56
  for index, row in sorted_references.iterrows():
57
+ if(type(row["user"]) is str and type(row['assistant']) is str):
58
+ try:
59
+ print(index)
60
+ print(f'{row["user"]}')
61
+ user = translator.translate(f'{row["user"]}', src='ar', dest='en').text
62
+ print(user)
63
+ #print(row['assistant'])
64
+ assistant = translator.translate(row['assistant']).text
65
+ #print(assistant)
66
+ messages.append({"role": "user", "content":user })
67
+ messages.append({"role": "assistant", "content": assistant})
68
+ except:
69
+ print("An exception occurred")
70
 
 
71
  #adding more references
72
  df = pd.read_csv("moslem-bot-reference.csv")
73
  for index, row in df.iterrows():