Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,12 @@ import requests
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
# Fetch the API token from the environment variable set in Hugging Face Space Secrets
|
| 6 |
API_TOKEN = os.getenv("HF_API_TOKEN")
|
| 7 |
if not API_TOKEN:
|
| 8 |
raise ValueError("HF_API_TOKEN not found. Please set it in the Space Secrets.")
|
| 9 |
|
| 10 |
-
# DeepSeek-R1 model endpoint
|
| 11 |
MODEL_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
|
| 12 |
|
| 13 |
-
# Headers for authentication
|
| 14 |
HEADERS = {
|
| 15 |
"Authorization": f"Bearer {API_TOKEN}",
|
| 16 |
"Content-Type": "application/json"
|
|
@@ -21,15 +18,15 @@ def query_deepseek(prompt):
|
|
| 21 |
payload = {
|
| 22 |
"inputs": prompt,
|
| 23 |
"parameters": {
|
| 24 |
-
"max_new_tokens": 100,
|
| 25 |
-
"temperature": 0.6,
|
| 26 |
-
"top_p": 0.9
|
| 27 |
}
|
| 28 |
}
|
| 29 |
|
| 30 |
try:
|
| 31 |
response = requests.post(MODEL_URL, headers=HEADERS, json=payload)
|
| 32 |
-
response.raise_for_status()
|
| 33 |
result = response.json()
|
| 34 |
return result[0]["generated_text"].strip()
|
| 35 |
except requests.exceptions.RequestException as e:
|
|
@@ -43,7 +40,6 @@ def chat_interface(user_input, history):
|
|
| 43 |
response = query_deepseek(prompt)
|
| 44 |
return response
|
| 45 |
|
| 46 |
-
# Custom CSS for blue buttons
|
| 47 |
css = """
|
| 48 |
button {
|
| 49 |
background-color: #007bff !important; /* Blue background */
|
|
@@ -57,7 +53,7 @@ button:hover {
|
|
| 57 |
}
|
| 58 |
"""
|
| 59 |
|
| 60 |
-
|
| 61 |
interface = gr.ChatInterface(
|
| 62 |
fn=chat_interface,
|
| 63 |
title="LocoBot : Your AI Companion",
|
|
|
|
| 2 |
import os
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
| 5 |
API_TOKEN = os.getenv("HF_API_TOKEN")
|
| 6 |
if not API_TOKEN:
|
| 7 |
raise ValueError("HF_API_TOKEN not found. Please set it in the Space Secrets.")
|
| 8 |
|
|
|
|
| 9 |
MODEL_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B"
|
| 10 |
|
|
|
|
| 11 |
HEADERS = {
|
| 12 |
"Authorization": f"Bearer {API_TOKEN}",
|
| 13 |
"Content-Type": "application/json"
|
|
|
|
| 18 |
payload = {
|
| 19 |
"inputs": prompt,
|
| 20 |
"parameters": {
|
| 21 |
+
"max_new_tokens": 100,
|
| 22 |
+
"temperature": 0.6,
|
| 23 |
+
"top_p": 0.9
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
| 27 |
try:
|
| 28 |
response = requests.post(MODEL_URL, headers=HEADERS, json=payload)
|
| 29 |
+
response.raise_for_status()
|
| 30 |
result = response.json()
|
| 31 |
return result[0]["generated_text"].strip()
|
| 32 |
except requests.exceptions.RequestException as e:
|
|
|
|
| 40 |
response = query_deepseek(prompt)
|
| 41 |
return response
|
| 42 |
|
|
|
|
| 43 |
css = """
|
| 44 |
button {
|
| 45 |
background-color: #007bff !important; /* Blue background */
|
|
|
|
| 53 |
}
|
| 54 |
"""
|
| 55 |
|
| 56 |
+
|
| 57 |
interface = gr.ChatInterface(
|
| 58 |
fn=chat_interface,
|
| 59 |
title="LocoBot : Your AI Companion",
|