Sandhya commited on
Commit
ae68c70
·
1 Parent(s): 289e125

First Commit

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -16,6 +16,8 @@ app.add_middleware(CORSMiddleware,allow_origins=["*"],allow_methods=["*"],allow_
16
 
17
  agent_instance: Optional[Agent]=None
18
  DEFAULT_PROVIDER:Literal['hf-inference']="hf-inference"
 
 
19
  async def get_agent():
20
  """Get or create the agent instance."""
21
  global agent_instance
@@ -38,11 +40,11 @@ async def get_agent():
38
  print(f"❌ Error creating/loading agent: {str(e)}")
39
  return agent_instance
40
 
41
- agent=get_agent()
42
-
43
  @app.on_event("startup")
44
  async def startup_event():
45
- await agent.load_tools()
 
 
46
 
47
  def chat_function(user_message,history,model_id):
48
 
@@ -59,10 +61,10 @@ def chat_function(user_message,history,model_id):
59
  First, run the tool `read_model_card` on repo_id `{model_id}` to get the model card.
60
  Then answer this user question based on the model card:
61
  User question: {user_message}"""
62
- history=history+[(user_message)]
63
  try:
64
  response=""
65
- for output in agent.run(prompt):
66
  if hasattr(output,"content") and output.content:
67
  response=output.content
68
  final_response=response or "⚠️ Sorry, I couldn't generate a response."
 
16
 
17
  agent_instance: Optional[Agent]=None
18
  DEFAULT_PROVIDER:Literal['hf-inference']="hf-inference"
19
+
20
+
21
  async def get_agent():
22
  """Get or create the agent instance."""
23
  global agent_instance
 
40
  print(f"❌ Error creating/loading agent: {str(e)}")
41
  return agent_instance
42
 
 
 
43
  @app.on_event("startup")
44
  async def startup_event():
45
+ global agent_instance
46
+ agent_instance = await get_agent()
47
+
48
 
49
  def chat_function(user_message,history,model_id):
50
 
 
61
  First, run the tool `read_model_card` on repo_id `{model_id}` to get the model card.
62
  Then answer this user question based on the model card:
63
  User question: {user_message}"""
64
+ history=history+[(user_message,None)]
65
  try:
66
  response=""
67
+ for output in agent_instance.run(prompt):
68
  if hasattr(output,"content") and output.content:
69
  response=output.content
70
  final_response=response or "⚠️ Sorry, I couldn't generate a response."