jsakshi commited on
Commit
0dc9778
·
verified ·
1 Parent(s): ae02656

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -23
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import requests
2
  import os
3
- import time
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 chatbot():
41
- """Simple chatbot loop for command-line interaction."""
42
- print("Welcome to the DeepSeek-R1 Chatbot! Type 'exit' to quit.")
43
- while True:
44
- user_input = input("You: ")
45
- if user_input.lower() == "exit":
46
- print("Goodbye!")
47
- break
48
-
49
- # Structure the prompt
50
- prompt = f"User: {user_input}\nAssistant: "
51
- print("Thinking...", end="\r")
52
-
53
- # Get response from DeepSeek-R1
54
- response = query_deepseek(prompt)
55
-
56
- # Clear "Thinking..." and display response
57
- print(" " * 20, end="\r")
58
- print(f"Bot: {response}")
59
-
60
- time.sleep(1)
 
 
 
 
 
 
 
 
 
61
 
62
  if __name__ == "__main__":
63
- chatbot()
 
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)