Synnove commited on
Commit
aba723a
·
verified ·
1 Parent(s): a66dae1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -7
app.py CHANGED
@@ -6,19 +6,57 @@ import pandas as pd
6
  #import smolagents #to test
7
  from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, HfApiModel, load_tool, tool, LLMFunction
8
  from huggingface_hub import InferenceClient
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  #Client setup
11
  #token = HF_TOKEN
12
  #model_repo_id = chat_completion eller question_answering
13
 
14
- llm = LLMFunction.from_huggingface_inference_api(
15
- repo_id="google/flan-t5-base", #
16
- token="HF_TOKEN "
17
- )
18
 
19
- agent = CodeAgent(llm=llm)
20
- response = agent("Translate 'How are you?' to German.")
21
- print(response)
22
 
23
 
24
 
 
6
  #import smolagents #to test
7
  from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool, HfApiModel, load_tool, tool, LLMFunction
8
  from huggingface_hub import InferenceClient
9
+ import json
10
+
11
+ api_url = "https://agents-course-unit4-scoring.hf.space"
12
+ 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
50
  #model_repo_id = chat_completion eller question_answering
51
 
52
+ # llm = LLMFunction.from_huggingface_inference_api(
53
+ # repo_id="google/flan-t5-base", #
54
+ # token="HF_TOKEN "
55
+ # )
56
 
57
+ # agent = CodeAgent(llm=llm)
58
+ # response = agent("Translate 'How are you?' to German.")
59
+ # print(response)
60
 
61
 
62