Duke-911 commited on
Commit
396e8b0
·
1 Parent(s): 81917a3

Use a simple LLM agent

Browse files
Files changed (2) hide show
  1. app.py +17 -9
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,23 +1,31 @@
1
  import os
2
  import gradio as gr
3
  import requests
4
- import inspect
5
  import pandas as pd
6
 
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
- # --- Basic Agent Definition ---
12
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
- class BasicAgent:
 
14
  def __init__(self):
15
- print("BasicAgent initialized.")
 
16
  def __call__(self, question: str) -> str:
17
  print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
@@ -40,7 +48,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
  try:
43
- agent = BasicAgent()
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
 
1
  import os
2
  import gradio as gr
3
  import requests
 
4
  import pandas as pd
5
 
6
+ from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
7
+
8
  # (Keep Constants as is)
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
+
13
+ llm = HuggingFaceInferenceAPI(model_name='Qwen/Qwen2.5-Coder-32B-Instruct')
14
+
15
+ class TofuAgent:
16
  def __init__(self):
17
+ print("Agent initialized.")
18
+
19
  def __call__(self, question: str) -> str:
20
  print(f"Agent received question (first 50 chars): {question[:50]}...")
21
+ try:
22
+ # Use the llm to generate an answer
23
+ response = llm.generate(question)
24
+ print(f"Agent generated response: {response}")
25
+ return response
26
+ except Exception as e:
27
+ print(f"Error generating response: {e}")
28
+ return f"Error: {e}"
29
 
30
  def run_and_submit_all( profile: gr.OAuthProfile | None):
31
  """
 
48
 
49
  # 1. Instantiate Agent ( modify this part to create your agent)
50
  try:
51
+ agent = TofuAgent()
52
  except Exception as e:
53
  print(f"Error instantiating agent: {e}")
54
  return f"Error initializing agent: {e}", None
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  gradio
2
- requests
 
 
1
  gradio
2
+ requests
3
+ pandas