deema commited on
Commit
7181cca
1 Parent(s): b8adfc6

update database call

Browse files
Files changed (2) hide show
  1. app.py +5 -4
  2. database.py +16 -5
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import os
2
  os.system("pip install pymongo")
 
 
3
  import gradio as gr
4
  import pandas as pd
5
  import random
6
- from collections import defaultdict
7
- from database import save_response
8
 
9
  css = """
10
  .rtl{
@@ -40,13 +40,13 @@ def process_rankings(user_rankings):
40
  model_rankings_dict = dict(model_rankings)
41
 
42
  save_response(model_rankings_dict)
 
 
43
  # file_path = 'users_ranking.txt'
44
  # with open(file_path, 'a') as file:
45
  # model_rankings_dict = dict(model_rankings)
46
  # json.dump(model_rankings_dict, file)
47
  # file.write('\n') # Add a newline to separate entries
48
- print("Updated Model Rankings:", model_rankings) # Debugging print
49
- return
50
 
51
 
52
  def get_questions_and_answers():
@@ -110,6 +110,7 @@ def rank_interface():
110
  user_rankings.append((model, j)) # j is the rank (1, 2, or 3)
111
  break
112
  process_rankings(user_rankings)
 
113
 
114
  return gr.Interface(fn=rank_fluency, inputs=inputs, outputs=outputs, title="ترتيب فصاحة النماذج",
115
  description=".لديك مجموعة من الأسئلة، الرجاء ترتيب إجابات كل سؤال حسب جودة و فصاحة الإجابة", css=css)
 
1
  import os
2
  os.system("pip install pymongo")
3
+ from collections import defaultdict
4
+ from database import save_response
5
  import gradio as gr
6
  import pandas as pd
7
  import random
 
 
8
 
9
  css = """
10
  .rtl{
 
40
  model_rankings_dict = dict(model_rankings)
41
 
42
  save_response(model_rankings_dict)
43
+ print("Updated Model Rankings:", model_rankings) # Debugging print
44
+ return
45
  # file_path = 'users_ranking.txt'
46
  # with open(file_path, 'a') as file:
47
  # model_rankings_dict = dict(model_rankings)
48
  # json.dump(model_rankings_dict, file)
49
  # file.write('\n') # Add a newline to separate entries
 
 
50
 
51
 
52
  def get_questions_and_answers():
 
110
  user_rankings.append((model, j)) # j is the rank (1, 2, or 3)
111
  break
112
  process_rankings(user_rankings)
113
+ return "سجلنا ردك، ما قصرت =)"
114
 
115
  return gr.Interface(fn=rank_fluency, inputs=inputs, outputs=outputs, title="ترتيب فصاحة النماذج",
116
  description=".لديك مجموعة من الأسئلة، الرجاء ترتيب إجابات كل سؤال حسب جودة و فصاحة الإجابة", css=css)
database.py CHANGED
@@ -1,8 +1,20 @@
 
1
 
2
- from pymongo.mongo_client import MongoClient
 
 
 
 
 
 
 
 
 
 
 
3
  # from pymongo.server_api import ServerApi
4
  # from urllib.parse import quote_plus
5
- # import ssl
6
  # from pymongo import MongoClient
7
 
8
  # uri = "mongodb+srv://cluster0.tzvxqk3.mongodb.net/?authSource=%24external&authMechanism=MONGODB-X509&retryWrites=true&w=majority"
@@ -16,7 +28,7 @@ from pymongo.mongo_client import MongoClient
16
  # # Create a new client and connect to the server
17
  # client = MongoClient(uri, server_api=ServerApi('1'))
18
 
19
- # Specify the database and collection
20
  # db = client.your_database_name
21
  # collection = db.your_collection_name
22
 
@@ -26,9 +38,8 @@ def save_response(response_data):
26
  try:
27
  # Insert the response data into the collection
28
  print("right before insertion")
29
- # collection.insert_one(response_data)
30
  print("right after insertion")
31
- return "سجلنا ردك، ما قصرت =)"
32
  except Exception as e:
33
  print(f"An error occurred: {e}")
34
  exit(0)
 
1
+ from pymongo import MongoClient
2
 
3
+ uri = "mongodb+srv://cluster0.tzvxqk3.mongodb.net/?authSource=%24external&authMechanism=MONGODB-X509&retryWrites=true&w=majority"
4
+ client = MongoClient(uri,
5
+ tls=True,
6
+ tlsCertificateKeyFile="X509-cert-2433626168795922546.pem")
7
+
8
+ db = client['testDB']
9
+ collection = db['testCol']
10
+
11
+
12
+ ################################################
13
+
14
+ # from pymongo.mongo_client import MongoClient
15
  # from pymongo.server_api import ServerApi
16
  # from urllib.parse import quote_plus
17
+ # # import ssl
18
  # from pymongo import MongoClient
19
 
20
  # uri = "mongodb+srv://cluster0.tzvxqk3.mongodb.net/?authSource=%24external&authMechanism=MONGODB-X509&retryWrites=true&w=majority"
 
28
  # # Create a new client and connect to the server
29
  # client = MongoClient(uri, server_api=ServerApi('1'))
30
 
31
+ # # Specify the database and collection
32
  # db = client.your_database_name
33
  # collection = db.your_collection_name
34
 
 
38
  try:
39
  # Insert the response data into the collection
40
  print("right before insertion")
41
+ collection.insert_one(response_data)
42
  print("right after insertion")
 
43
  except Exception as e:
44
  print(f"An error occurred: {e}")
45
  exit(0)