Spaces:
Sleeping
Sleeping
Sandhya
commited on
Commit
·
9142873
1
Parent(s):
f5dcbeb
First Commit
Browse files
app.py
CHANGED
|
@@ -49,18 +49,21 @@ async def get_agent():
|
|
| 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
|
| 56 |
agent_instance = await get_agent()
|
| 57 |
|
| 58 |
|
|
|
|
| 59 |
async def chat_function(user_message, history, model_id):
|
|
|
|
|
|
|
|
|
|
| 60 |
prompt=f"""You're an assistant helping with hugging face model cards.
|
| 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 = ""
|
|
@@ -81,10 +84,10 @@ def create_gradio_app():
|
|
| 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")
|
| 84 |
-
user_input=gr.Textbox(label="Your Question",
|
| 85 |
send=gr.Button("Ask")
|
| 86 |
chatbot=gr.Chatbot(label="chat")
|
| 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="/")
|
|
|
|
| 49 |
print(f"❌ Error creating/loading agent: {str(e)}")
|
| 50 |
return agent_instance
|
| 51 |
|
|
|
|
| 52 |
@app.on_event("startup")
|
| 53 |
async def startup_event():
|
| 54 |
global agent_instance
|
| 55 |
agent_instance = await get_agent()
|
| 56 |
|
| 57 |
|
| 58 |
+
|
| 59 |
async def chat_function(user_message, history, model_id):
|
| 60 |
+
global agent_instance
|
| 61 |
+
if agent_instance is None:
|
| 62 |
+
agent_instance = await get_agent()
|
| 63 |
prompt=f"""You're an assistant helping with hugging face model cards.
|
| 64 |
+
First, run the tool `read_model_card` on repo_id `{model_id}` to get the model card.
|
| 65 |
+
Then answer this user question based on the model card:
|
| 66 |
+
User question: {user_message}"""
|
| 67 |
history = history + [(user_message, None)]
|
| 68 |
try:
|
| 69 |
response = ""
|
|
|
|
| 84 |
gr.Markdown("## 🤖 Model Card Chatbot\nAsk questions about Hugging Face model card")
|
| 85 |
with gr.Row():
|
| 86 |
model_id=gr.Textbox(label="MODEL ID", value="google/gemma-2-2b")
|
| 87 |
+
user_input=gr.Textbox(label="Your Question",placeholder="Ask something about the model card .....")
|
| 88 |
send=gr.Button("Ask")
|
| 89 |
chatbot=gr.Chatbot(label="chat")
|
| 90 |
+
send.click(fn=chat_function, inputs=[user_input,chatbot,model_id], outputs=[chatbot,user_input])
|
| 91 |
return demo
|
| 92 |
gradio_app=create_gradio_app()
|
| 93 |
app=gr.mount_gradio_app(app,gradio_app,path="/")
|