Sandhya commited on
Commit
6f06d33
·
1 Parent(s): 79ae0c1

First Commit

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -12,7 +12,7 @@ load_dotenv()
12
  HF_TOKEN=os.getenv("HF_TOKEN")
13
  HF_MODEL=os.getenv("HF_MODEL","google/gemma-2-2b")
14
  app=FastAPI(title="MODEL-CARD-CHATBOT")
15
- app.add_middleware(CORSMiddleware,allow_origins=["*"])
16
 
17
  agent_instance: Optional[Agent]=None
18
  DEFAULT_PROVIDER:Literal['hf-inference']="hf-inference"
@@ -40,11 +40,9 @@ async def get_agent():
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
@@ -77,15 +75,14 @@ def chat_function(user_message, history, model_id):
77
 
78
 
79
  def create_gradio_app():
80
- with gr.Blocks(title="Model Card Chatbot",css=".gr-box{max-width: 800px; margin: auto;}") as demo:
81
  gr.Markdown("## 🤖 Model Card Chatbot\nAsk questions about Hugging Face model card")
82
- with gr.Row():
83
- model_id=gr.Textbox(label="MODEL ID", value="google/gemma-2-2b",scale=2)
84
- user_input=gr.Textbox(label="Your Question",placeholder="Ask something about the model card .....",lines=1, scale=3)
85
- send=gr.Button("Ask")
86
- chatbot=gr.Chatbot(label="chat",height=50)
87
- send.click(fn=chat_function, inputs=[user_input,chatbot,model_id], outputs=[chatbot,user_input])
88
- return demo
89
  gradio_app=create_gradio_app()
90
  app=gr.mount_gradio_app(app,gradio_app,path="/")
91
 
 
12
  HF_TOKEN=os.getenv("HF_TOKEN")
13
  HF_MODEL=os.getenv("HF_MODEL","google/gemma-2-2b")
14
  app=FastAPI(title="MODEL-CARD-CHATBOT")
15
+ app.add_middleware(CORSMiddleware, allow_origins=["*"], allow_methods=['*'], allow_headers=['*'])
16
 
17
  agent_instance: Optional[Agent]=None
18
  DEFAULT_PROVIDER:Literal['hf-inference']="hf-inference"
 
40
  }
41
  }]
42
  )
 
 
43
  await agent.load_tools()
44
  agent_instance = agent
45
+ print("✅ Agent is ready")
46
  except Exception as e:
47
  print(f"❌ Error creating/loading agent: {str(e)}")
48
  return agent_instance
 
75
 
76
 
77
  def create_gradio_app():
78
+ with gr.Blocks(title="Model Card Chatbot") as demo:
79
  gr.Markdown("## 🤖 Model Card Chatbot\nAsk questions about Hugging Face model card")
80
+ model_id=gr.Textbox(label="MODEL ID", value="google/gemma-2-2b")
81
+ user_input=gr.Textbox(label="Your Question",placeholder="Ask something about the model card")
82
+ send=gr.Button("Ask")
83
+ chatbot=gr.Chatbot(label="chat")
84
+ send.click(fn=chat_function, inputs=[user_input,chatbot,model_id], outputs=[chatbot,user_input])
85
+ return demo
 
86
  gradio_app=create_gradio_app()
87
  app=gr.mount_gradio_app(app,gradio_app,path="/")
88