Synnove commited on
Commit
2d114c5
·
verified ·
1 Parent(s): 957202d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -25
app.py CHANGED
@@ -13,37 +13,60 @@ questions_url = f"{api_url}/questions"
13
  submit_url = f"{api_url}/submit"
14
 
15
 
16
- # 2. Fetch Questions
17
- def call_api():
18
- print(f"Fetching questions from: {questions_url}")
19
  try:
20
- response = requests.get(questions_url, timeout=15)
21
- response.raise_for_status()
22
- questions_data = response.json()
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- if not questions_data:
25
- print("Fetched questions list is empty.")
26
- return "Fetched questions list is empty or invalid format.", None
27
-
28
- print(f"Fetched {len(questions_data)} questions.")
 
 
 
29
 
30
- with open("questions.json", "w", encoding="utf-8") as f:
31
- json.dump(questions_data, f, indent=4)
32
- print("Questions saved to questions.json")
 
33
 
34
- except requests.exceptions.RequestException as e:
35
- print(f"Error fetching questions: {e}")
36
- return f"Error fetching questions: {e}", None
37
- except requests.exceptions.JSONDecodeError as e:
38
- print(f"Error decoding JSON response from questions endpoint: {e}")
39
- print(f"Response text: {response.text[:500]}")
40
- return f"Error decoding server response for questions: {e}", None
41
-
42
  except Exception as e:
43
- print(f"An unexpected error occurred fetching questions: {e}")
44
- return f"An unexpected error occurred fetching questions: {e}", None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- call_api()
47
 
48
  #Client setup
49
  #token = HF_TOKEN
 
13
  submit_url = f"{api_url}/submit"
14
 
15
 
16
+ def load_questions_from_file(filepath="questions.json"):
 
 
17
  try:
18
+ with open(filepath, "r", encoding="utf-8") as f:
19
+ questions_data = json.load(f)
20
+ if not questions_data:
21
+ print("Loaded file is empty.")
22
+ return "Loaded file is empty.", None
23
+ print(f"Loaded {len(questions_data)} questions from file.")
24
+ return "Loaded questions successfully.", questions_data
25
+ except FileNotFoundError:
26
+ print("File not found. Please run the API fetch first.")
27
+ return "File not found.", None
28
+ except json.JSONDecodeError as e:
29
+ print(f"Error decoding JSON: {e}")
30
+ return f"Error decoding JSON: {e}", None
31
+ except Exception as e:
32
+ print(f"Unexpected error: {e}")
33
+ return f"Unexpected error: {e}", None
34
 
35
+ #set up
36
+ #token
37
+
38
+ #Model
39
+
40
+ #Agent
41
+
42
+ #
43
 
44
+ def run_and_submit_one():
45
+ # 1. Instantiate Agent ( modify this part to create your agent)
46
+ try:
47
+ agent = TransformerAgent()
48
 
 
 
 
 
 
 
 
 
49
  except Exception as e:
50
+ print(f"Error instantiating agent: {e}")
51
+ return f"Error initializing agent: {e}", None
52
+
53
+ # 2. Fetch Questions by loading from local json
54
+ status_message, questions_data = load_questions_from_file()
55
+
56
+ if questions_data is not None and len(questions_data) > 0:
57
+ first_question = questions_data[0]
58
+ print("First question object:", first_question)
59
+
60
+ #To test
61
+ question_text = first_question.get("question")
62
+ task_id = first_question.get("task_id")
63
+ print(f"\nTask ID: {task_id}")
64
+ print(f"Question: {question_text}")
65
+ else:
66
+ print("No data found.")
67
+
68
+ run_and_submit_one()
69
 
 
70
 
71
  #Client setup
72
  #token = HF_TOKEN