Sandhya commited on
Commit
060bc2f
·
1 Parent(s): 707ec96

first commit

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -62,7 +62,6 @@ First, run the tool `read_model_card` on repo_id `{model_id}` to get the model c
62
  Then answer this user question based on the model card:
63
  User question: {user_message}
64
  """
65
- history = history + [(user_message, None)]
66
  try:
67
  response = ""
68
  outputs = agent_instance.run(prompt)
@@ -71,13 +70,15 @@ User question: {user_message}
71
  response = output.content
72
  if not response:
73
  response = "⚠️ Sorry, I couldn't generate a response."
74
- history[-1] = (user_message, response)
 
75
  except Exception as e:
76
- history[-1] = (user_message, f"⚠️ Error: {str(e)}")
 
77
  return history, ""
78
 
79
  def create_gradio_app():
80
- with gr.Blocks(theme=gr.themes.Soft(), title="🤖 Model Card Chatbot") as demo:
81
  gr.Markdown("""
82
  # 🤖 **Model Card Chatbot**
83
  Ask anything about a model's card on Hugging Face.
@@ -86,7 +87,7 @@ def create_gradio_app():
86
  model_id = gr.Textbox(label="Model ID", value="google/gemma-2-2b", scale=2)
87
  user_input = gr.Textbox(label="Your Question", placeholder="e.g., What is this model trained on?", scale=3)
88
  send = gr.Button("🔍 Ask", scale=1)
89
- chatbot = gr.Chatbot(label="Chat")
90
 
91
  send.click(
92
  fn=chat_function,
 
62
  Then answer this user question based on the model card:
63
  User question: {user_message}
64
  """
 
65
  try:
66
  response = ""
67
  outputs = agent_instance.run(prompt)
 
70
  response = output.content
71
  if not response:
72
  response = "⚠️ Sorry, I couldn't generate a response."
73
+ history = history + [{"role": "user", "content": user_message}]
74
+ history.append({"role": "assistant", "content": response})
75
  except Exception as e:
76
+ history = history + [{"role": "user", "content": user_message}]
77
+ history.append({"role": "assistant", "content": f"⚠️ Error: {str(e)}"})
78
  return history, ""
79
 
80
  def create_gradio_app():
81
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="violet"), title="🤖 Model Card Chatbot") as demo:
82
  gr.Markdown("""
83
  # 🤖 **Model Card Chatbot**
84
  Ask anything about a model's card on Hugging Face.
 
87
  model_id = gr.Textbox(label="Model ID", value="google/gemma-2-2b", scale=2)
88
  user_input = gr.Textbox(label="Your Question", placeholder="e.g., What is this model trained on?", scale=3)
89
  send = gr.Button("🔍 Ask", scale=1)
90
+ chatbot = gr.Chatbot(label="Chat", type="messages")
91
 
92
  send.click(
93
  fn=chat_function,