Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import requests
|
| 2 |
import os
|
| 3 |
-
import
|
| 4 |
|
| 5 |
# Fetch the API token from the environment variable set in Hugging Face Space Secrets
|
| 6 |
API_TOKEN = os.getenv("HF_API_TOKEN")
|
|
@@ -37,27 +37,36 @@ def query_deepseek(prompt):
|
|
| 37 |
except (KeyError, IndexError):
|
| 38 |
return "Error: Unexpected response format from API"
|
| 39 |
|
| 40 |
-
def
|
| 41 |
-
"""
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
|
|
|
|
| 1 |
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")
|
|
|
|
| 37 |
except (KeyError, IndexError):
|
| 38 |
return "Error: Unexpected response format from API"
|
| 39 |
|
| 40 |
+
def chat_interface(user_input, history):
|
| 41 |
+
"""Handle chatbot interaction with Gradio."""
|
| 42 |
+
prompt = f"User: {user_input}\nAssistant: "
|
| 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 */
|
| 50 |
+
color: white !important; /* White text */
|
| 51 |
+
border: none !important;
|
| 52 |
+
padding: 10px 20px !important;
|
| 53 |
+
border-radius: 5px !important;
|
| 54 |
+
}
|
| 55 |
+
button:hover {
|
| 56 |
+
background-color: #0056b3 !important; /* Darker blue on hover */
|
| 57 |
+
}
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
# Create Gradio interface
|
| 61 |
+
interface = gr.ChatInterface(
|
| 62 |
+
fn=chat_interface,
|
| 63 |
+
title="LocoBot: DeepSeek-R1 Chatbot",
|
| 64 |
+
description="Chat with DeepSeek-R1 powered by Hugging Face Inference API.",
|
| 65 |
+
theme="default",
|
| 66 |
+
css=css,
|
| 67 |
+
submit_btn="Send",
|
| 68 |
+
clear_btn="Clear Chat"
|
| 69 |
+
)
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
| 72 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|