Spaces:
Running
Running
Commit
·
cb4656b
1
Parent(s):
fc33bcb
placed1
Browse files
app.py
CHANGED
|
@@ -10,8 +10,8 @@ from huggingface_hub import hf_hub_download
|
|
| 10 |
# -----------------------------
|
| 11 |
# Load API key from Hugging Face Secrets
|
| 12 |
# -----------------------------
|
| 13 |
-
|
| 14 |
-
|
| 15 |
|
| 16 |
# -----------------------------
|
| 17 |
# Load TFLite model from Hugging Face Hub
|
|
@@ -56,20 +56,20 @@ def predict_image_class(image):
|
|
| 56 |
# -----------------------------
|
| 57 |
# OpenAI Chatbot (single-turn, no history)
|
| 58 |
# -----------------------------
|
| 59 |
-
def
|
| 60 |
payload = {
|
| 61 |
-
"model": "gpt-
|
| 62 |
"messages": [{"role": "user", "content": user_message}],
|
| 63 |
"temperature": 0.7,
|
| 64 |
"max_tokens": 500
|
| 65 |
}
|
| 66 |
|
| 67 |
headers = {
|
| 68 |
-
"Authorization": f"Bearer {
|
| 69 |
"Content-Type": "application/json"
|
| 70 |
}
|
| 71 |
|
| 72 |
-
response = requests.post(
|
| 73 |
|
| 74 |
if response.status_code == 200:
|
| 75 |
bot_message = response.json()["choices"][0]["message"]["content"]
|
|
@@ -103,7 +103,7 @@ with gr.Blocks(title="🌱 Plant Disease Classifier & AI Chatbot (OpenAI)") as d
|
|
| 103 |
response_box = gr.Textbox(label="Bot Response", lines=5)
|
| 104 |
send_btn = gr.Button("Send")
|
| 105 |
|
| 106 |
-
send_btn.click(
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
demo.launch()
|
|
|
|
| 10 |
# -----------------------------
|
| 11 |
# Load API key from Hugging Face Secrets
|
| 12 |
# -----------------------------
|
| 13 |
+
GROK_KEY = os.getenv("GROK_API_KEY")
|
| 14 |
+
GROK_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 15 |
|
| 16 |
# -----------------------------
|
| 17 |
# Load TFLite model from Hugging Face Hub
|
|
|
|
| 56 |
# -----------------------------
|
| 57 |
# OpenAI Chatbot (single-turn, no history)
|
| 58 |
# -----------------------------
|
| 59 |
+
def grok_chatbot(user_message):
|
| 60 |
payload = {
|
| 61 |
+
"model": "openai/gpt-oss-20b", # ✅ lightweight, works in Spaces
|
| 62 |
"messages": [{"role": "user", "content": user_message}],
|
| 63 |
"temperature": 0.7,
|
| 64 |
"max_tokens": 500
|
| 65 |
}
|
| 66 |
|
| 67 |
headers = {
|
| 68 |
+
"Authorization": f"Bearer {GROK_KEY}",
|
| 69 |
"Content-Type": "application/json"
|
| 70 |
}
|
| 71 |
|
| 72 |
+
response = requests.post(GROK_URL, headers=headers, json=payload)
|
| 73 |
|
| 74 |
if response.status_code == 200:
|
| 75 |
bot_message = response.json()["choices"][0]["message"]["content"]
|
|
|
|
| 103 |
response_box = gr.Textbox(label="Bot Response", lines=5)
|
| 104 |
send_btn = gr.Button("Send")
|
| 105 |
|
| 106 |
+
send_btn.click(grok_chatbot, inputs=msg, outputs=response_box)
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
demo.launch()
|