Update app.py
Browse files
app.py
CHANGED
@@ -1,42 +1,34 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
from transformers import pipeline
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
-
# Load environment variables from .env
|
7 |
load_dotenv()
|
8 |
PASSWORD = os.getenv("ARMAAN_PASS")
|
9 |
|
10 |
-
# Load
|
11 |
-
chatbot = pipeline("
|
|
|
12 |
|
13 |
-
# Global system prompt (admin-editable)
|
14 |
-
system_prompt = "You are a helpful assistant."
|
15 |
-
|
16 |
-
# Chat function
|
17 |
def chat_fn(message, history):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return reply
|
22 |
|
23 |
-
# Password check
|
24 |
def check_password(pass_input):
|
25 |
if pass_input == PASSWORD:
|
26 |
return gr.update(visible=True), ""
|
27 |
else:
|
28 |
return gr.update(visible=False), "Incorrect password"
|
29 |
|
30 |
-
# Prompt update
|
31 |
def update_prompt(new_prompt):
|
32 |
global system_prompt
|
33 |
system_prompt = new_prompt
|
34 |
-
return "Prompt updated
|
35 |
|
36 |
-
# Gradio UI
|
37 |
with gr.Blocks() as demo:
|
38 |
-
gr.Markdown("#
|
39 |
-
|
40 |
with gr.Tab("Chat"):
|
41 |
gr.ChatInterface(fn=chat_fn)
|
42 |
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from transformers import pipeline, Conversation
|
4 |
from dotenv import load_dotenv
|
5 |
|
|
|
6 |
load_dotenv()
|
7 |
PASSWORD = os.getenv("ARMAAN_PASS")
|
8 |
|
9 |
+
# Load fast model
|
10 |
+
chatbot = pipeline("conversational", model="facebook/blenderbot-1B-distill")
|
11 |
+
system_prompt = "You are a helpful chatbot."
|
12 |
|
|
|
|
|
|
|
|
|
13 |
def chat_fn(message, history):
|
14 |
+
convo = Conversation(f"{message}")
|
15 |
+
result = chatbot(convo)
|
16 |
+
return result.generated_responses[-1]
|
|
|
17 |
|
|
|
18 |
def check_password(pass_input):
|
19 |
if pass_input == PASSWORD:
|
20 |
return gr.update(visible=True), ""
|
21 |
else:
|
22 |
return gr.update(visible=False), "Incorrect password"
|
23 |
|
|
|
24 |
def update_prompt(new_prompt):
|
25 |
global system_prompt
|
26 |
system_prompt = new_prompt
|
27 |
+
return "Prompt updated."
|
28 |
|
|
|
29 |
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("# Chatbot (Fast CPU-Friendly)")
|
31 |
+
|
32 |
with gr.Tab("Chat"):
|
33 |
gr.ChatInterface(fn=chat_fn)
|
34 |
|