Bijay13 commited on
Commit
328c6ef
·
verified ·
1 Parent(s): 1a810e1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -8
app.py CHANGED
@@ -64,17 +64,32 @@ def reset_conversation():
64
  conversation_chain = None
65
  return None
66
 
 
 
 
67
  with gr.Blocks(title="LangChain Groq Chatbot") as demo:
68
  gr.Markdown("# 🤖 LangChain Groq Chatbot")
69
  gr.Markdown("Chat with an AI assistant powered by LangChain and Groq")
70
 
71
- with gr.Row():
 
 
 
 
 
 
 
 
 
 
72
  api_key_input = gr.Textbox(
73
- label="Groq API Key",
74
- placeholder="Enter your Groq API key here...",
75
  type="password",
76
- value=os.getenv("GROQ_API_KEY", "")
 
 
77
  )
 
78
 
79
  chatbot = gr.Chatbot(height=400)
80
 
@@ -89,10 +104,14 @@ with gr.Blocks(title="LangChain Groq Chatbot") as demo:
89
  with gr.Row():
90
  clear_btn = gr.Button("Clear Conversation")
91
 
92
- gr.Markdown("### Instructions:")
93
- gr.Markdown("1. Get a free API key from [Groq Console](https://console.groq.com)")
94
- gr.Markdown("2. Enter your API key above")
95
- gr.Markdown("3. Start chatting!")
 
 
 
 
96
 
97
  def respond(message, chat_history, api_key):
98
  if not message.strip():
 
64
  conversation_chain = None
65
  return None
66
 
67
+ # Get API key from Hugging Face Secrets (environment variables)
68
+ DEFAULT_API_KEY = os.getenv("GROQ_API_KEY", "")
69
+
70
  with gr.Blocks(title="LangChain Groq Chatbot") as demo:
71
  gr.Markdown("# 🤖 LangChain Groq Chatbot")
72
  gr.Markdown("Chat with an AI assistant powered by LangChain and Groq")
73
 
74
+ # Only show API key input if not set in environment
75
+ if not DEFAULT_API_KEY:
76
+ with gr.Row():
77
+ api_key_input = gr.Textbox(
78
+ label="Groq API Key",
79
+ placeholder="Enter your Groq API key here...",
80
+ type="password",
81
+ value=""
82
+ )
83
+ else:
84
+ # Use hidden component with default key from environment
85
  api_key_input = gr.Textbox(
86
+ label="Groq API Key (Loaded from Environment)",
 
87
  type="password",
88
+ value=DEFAULT_API_KEY,
89
+ interactive=False,
90
+ visible=True
91
  )
92
+ gr.Markdown("✅ API Key loaded from environment variables")
93
 
94
  chatbot = gr.Chatbot(height=400)
95
 
 
104
  with gr.Row():
105
  clear_btn = gr.Button("Clear Conversation")
106
 
107
+ if not DEFAULT_API_KEY:
108
+ gr.Markdown("### Instructions:")
109
+ gr.Markdown("1. Get a free API key from [Groq Console](https://console.groq.com)")
110
+ gr.Markdown("2. Enter your API key above")
111
+ gr.Markdown("3. Start chatting!")
112
+ else:
113
+ gr.Markdown("### Ready to Chat!")
114
+ gr.Markdown("Your API key is configured. Start chatting below!")
115
 
116
  def respond(message, chat_history, api_key):
117
  if not message.strip():