Update app.py
Browse files
app.py
CHANGED
|
@@ -102,8 +102,8 @@ def query_deepseek(prompt):
|
|
| 102 |
response = requests.post(MODEL_URL, headers=HEADERS, json=payload)
|
| 103 |
response.raise_for_status()
|
| 104 |
result = response.json()
|
| 105 |
-
|
| 106 |
-
return
|
| 107 |
except requests.exceptions.RequestException as e:
|
| 108 |
return f"Error: Could not connect to the API - {str(e)}"
|
| 109 |
except (KeyError, IndexError):
|
|
@@ -111,61 +111,75 @@ def query_deepseek(prompt):
|
|
| 111 |
|
| 112 |
def chat_interface(user_input, history):
|
| 113 |
"""Handle chatbot interaction with Gradio."""
|
| 114 |
-
# Construct
|
| 115 |
if history:
|
| 116 |
prompt = "\n".join([f"User: {h[0]}\nAssistant: {h[1]}" for h in history]) + f"\nUser: {user_input}\nAssistant: "
|
| 117 |
else:
|
| 118 |
prompt = f"User: {user_input}\nAssistant: "
|
| 119 |
|
|
|
|
| 120 |
response = query_deepseek(prompt)
|
| 121 |
-
|
|
|
|
| 122 |
if response.startswith(prompt):
|
| 123 |
response = response[len(prompt):].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
return response
|
| 125 |
|
| 126 |
-
#
|
| 127 |
css = """
|
| 128 |
body {
|
| 129 |
-
background:
|
|
|
|
| 130 |
font-family: 'Arial', sans-serif;
|
| 131 |
}
|
| 132 |
|
| 133 |
.gr-chat-interface {
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
background: rgba(255, 255, 255, 0.9);
|
| 137 |
-
padding: 20px;
|
| 138 |
}
|
| 139 |
|
| 140 |
-
button {
|
| 141 |
-
background-color: #007bff !important; /*
|
| 142 |
color: white !important;
|
| 143 |
border: none !important;
|
| 144 |
-
padding:
|
| 145 |
-
border-radius:
|
| 146 |
-
font-weight: bold;
|
| 147 |
-
transition: all 0.3s ease;
|
| 148 |
}
|
| 149 |
|
| 150 |
-
button:hover {
|
| 151 |
background-color: #0056b3 !important; /* Darker blue on hover */
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
}
|
| 154 |
|
| 155 |
input, textarea {
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
| 158 |
padding: 10px !important;
|
| 159 |
}
|
| 160 |
|
| 161 |
.title {
|
| 162 |
-
color:
|
| 163 |
-
|
| 164 |
-
font-size: 2em;
|
| 165 |
}
|
| 166 |
|
| 167 |
.description {
|
| 168 |
-
color:
|
| 169 |
font-style: italic;
|
| 170 |
}
|
| 171 |
"""
|
|
@@ -176,7 +190,8 @@ interface = gr.ChatInterface(
|
|
| 176 |
title="LocoBot: DeepSeek-R1 Chatbot",
|
| 177 |
description="Chat with DeepSeek-R1 powered by Hugging Face Inference API.",
|
| 178 |
theme="default",
|
| 179 |
-
css=css
|
|
|
|
| 180 |
)
|
| 181 |
|
| 182 |
if __name__ == "__main__":
|
|
|
|
| 102 |
response = requests.post(MODEL_URL, headers=HEADERS, json=payload)
|
| 103 |
response.raise_for_status()
|
| 104 |
result = response.json()
|
| 105 |
+
generated_text = result[0]["generated_text"].strip()
|
| 106 |
+
return generated_text
|
| 107 |
except requests.exceptions.RequestException as e:
|
| 108 |
return f"Error: Could not connect to the API - {str(e)}"
|
| 109 |
except (KeyError, IndexError):
|
|
|
|
| 111 |
|
| 112 |
def chat_interface(user_input, history):
|
| 113 |
"""Handle chatbot interaction with Gradio."""
|
| 114 |
+
# Construct a clean prompt
|
| 115 |
if history:
|
| 116 |
prompt = "\n".join([f"User: {h[0]}\nAssistant: {h[1]}" for h in history]) + f"\nUser: {user_input}\nAssistant: "
|
| 117 |
else:
|
| 118 |
prompt = f"User: {user_input}\nAssistant: "
|
| 119 |
|
| 120 |
+
# Get the response
|
| 121 |
response = query_deepseek(prompt)
|
| 122 |
+
|
| 123 |
+
# Strip the prompt to avoid duplication
|
| 124 |
if response.startswith(prompt):
|
| 125 |
response = response[len(prompt):].strip()
|
| 126 |
+
|
| 127 |
+
# Deduplicate sentences
|
| 128 |
+
sentences = response.split(". ")
|
| 129 |
+
unique_sentences = []
|
| 130 |
+
[unique_sentences.append(s) for s in sentences if s not in unique_sentences]
|
| 131 |
+
response = ". ".join(unique_sentences).strip()
|
| 132 |
+
|
| 133 |
return response
|
| 134 |
|
| 135 |
+
# Simplified black-and-white CSS with a blue send button
|
| 136 |
css = """
|
| 137 |
body {
|
| 138 |
+
background: white; /* Plain white background */
|
| 139 |
+
color: black; /* Black text */
|
| 140 |
font-family: 'Arial', sans-serif;
|
| 141 |
}
|
| 142 |
|
| 143 |
.gr-chat-interface {
|
| 144 |
+
background: white;
|
| 145 |
+
color: black;
|
|
|
|
|
|
|
| 146 |
}
|
| 147 |
|
| 148 |
+
button#submit_btn { /* Target the send button specifically */
|
| 149 |
+
background-color: #007bff !important; /* Blue send button */
|
| 150 |
color: white !important;
|
| 151 |
border: none !important;
|
| 152 |
+
padding: 10px 20px !important;
|
| 153 |
+
border-radius: 5px !important;
|
|
|
|
|
|
|
| 154 |
}
|
| 155 |
|
| 156 |
+
button#submit_btn:hover {
|
| 157 |
background-color: #0056b3 !important; /* Darker blue on hover */
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
button { /* Other buttons remain black and white */
|
| 161 |
+
background-color: white !important;
|
| 162 |
+
color: black !important;
|
| 163 |
+
border: 1px solid black !important;
|
| 164 |
+
padding: 10px 20px !important;
|
| 165 |
+
border-radius: 5px !important;
|
| 166 |
}
|
| 167 |
|
| 168 |
input, textarea {
|
| 169 |
+
background: white !important;
|
| 170 |
+
color: black !important;
|
| 171 |
+
border: 1px solid black !important;
|
| 172 |
+
border-radius: 5px !important;
|
| 173 |
padding: 10px !important;
|
| 174 |
}
|
| 175 |
|
| 176 |
.title {
|
| 177 |
+
color: black;
|
| 178 |
+
font-size: 1.5em;
|
|
|
|
| 179 |
}
|
| 180 |
|
| 181 |
.description {
|
| 182 |
+
color: black;
|
| 183 |
font-style: italic;
|
| 184 |
}
|
| 185 |
"""
|
|
|
|
| 190 |
title="LocoBot: DeepSeek-R1 Chatbot",
|
| 191 |
description="Chat with DeepSeek-R1 powered by Hugging Face Inference API.",
|
| 192 |
theme="default",
|
| 193 |
+
css=css,
|
| 194 |
+
submit_btn=gr.Button("Send", elem_id="submit_btn") # Custom send button with ID
|
| 195 |
)
|
| 196 |
|
| 197 |
if __name__ == "__main__":
|