Sandhya commited on
Commit
c0705f0
·
1 Parent(s): 715b925

First Commit

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -19,7 +19,6 @@ 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
24
  if agent_instance is None and HF_TOKEN:
25
  print("🔧 Creating new Agent instance ...")
@@ -27,19 +26,30 @@ async def get_agent():
27
  print(f"🤖 Model: {HF_MODEL}")
28
  print(f"Provider: {DEFAULT_PROVIDER}")
29
  try:
30
- agent=Agent(model=HF_MODEL,provider="hf-inference",api_key=HF_TOKEN,
31
- servers=[{"type":"stdio","config":{
32
- "command":"python",
33
- "args":["mcp_server.py"],"cwd":".","env":{"HF_TOKEN": HF_TOKEN} if HF_TOKEN else {}}}])
 
 
 
 
 
 
 
 
 
 
34
  print("🚀 Agent instance created successfully")
35
  print("🔁 loading tools ...")
36
- await agent_instance.load_tools()
 
37
  print("✅ Tools loaded successfully")
38
-
39
  except Exception as e:
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
@@ -80,10 +90,10 @@ def create_gradio_app():
80
  gr.Markdown("## 🤖 Model Card Chatbot\nAsk questions about Hugging Face model card")
81
  with gr.Row():
82
  model_id=gr.Textbox(label="MODEL ID", value="google/gemma-2-2b")
83
- user_input=gr.Textbox(label="Your Question")
84
  send=gr.Button("Ask")
85
  output=gr.Markdown()
86
- send.click(fn=chat_function,inputs=[user_input,model_id],outputs=output)
87
  return demo
88
  gradio_app=create_gradio_app()
89
  app=gr.mount_gradio_app(app,gradio_app,path="/")
 
19
 
20
 
21
  async def get_agent():
 
22
  global agent_instance
23
  if agent_instance is None and HF_TOKEN:
24
  print("🔧 Creating new Agent instance ...")
 
26
  print(f"🤖 Model: {HF_MODEL}")
27
  print(f"Provider: {DEFAULT_PROVIDER}")
28
  try:
29
+ agent = Agent(
30
+ model=HF_MODEL,
31
+ provider="hf-inference",
32
+ api_key=HF_TOKEN,
33
+ servers=[{
34
+ "type": "stdio",
35
+ "config": {
36
+ "command": "python",
37
+ "args": ["mcp_server.py"],
38
+ "cwd": ".",
39
+ "env": {"HF_TOKEN": HF_TOKEN} if HF_TOKEN else {}
40
+ }
41
+ }]
42
+ )
43
  print("🚀 Agent instance created successfully")
44
  print("🔁 loading tools ...")
45
+ await agent.load_tools()
46
+ agent_instance = agent
47
  print("✅ Tools loaded successfully")
 
48
  except Exception as e:
49
  print(f"❌ Error creating/loading agent: {str(e)}")
50
  return agent_instance
51
 
52
+
53
  @app.on_event("startup")
54
  async def startup_event():
55
  global agent_instance
 
90
  gr.Markdown("## 🤖 Model Card Chatbot\nAsk questions about Hugging Face model card")
91
  with gr.Row():
92
  model_id=gr.Textbox(label="MODEL ID", value="google/gemma-2-2b")
93
+ user_input=gr.Textbox(label="Your Question",value="Ask something about the model card .....")
94
  send=gr.Button("Ask")
95
  output=gr.Markdown()
96
+ send.click(fn=chat_function,inputs=[user_input,output,model_id],outputs=[output,user_input])
97
  return demo
98
  gradio_app=create_gradio_app()
99
  app=gr.mount_gradio_app(app,gradio_app,path="/")