armaanuu commited on
Commit
e9ecab4
·
verified ·
1 Parent(s): a6b915d

Rename .env to app.py

Browse files
Files changed (2) hide show
  1. .env +0 -1
  2. app.py +57 -0
.env DELETED
@@ -1 +0,0 @@
1
- ARMAAN_PASS=armaanisop
 
 
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 chatbot pipeline
11
+ chatbot = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta")
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
+ full_prompt = f"{system_prompt}\nUser: {message}\nBot:"
19
+ response = chatbot(full_prompt, max_new_tokens=200, do_sample=True, temperature=0.7)[0]["generated_text"]
20
+ reply = response.split("Bot:")[-1].strip()
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 successfully."
35
+
36
+ # Gradio UI
37
+ with gr.Blocks() as demo:
38
+ gr.Markdown("# ChatGPT-Style Chatbot")
39
+
40
+ with gr.Tab("Chat"):
41
+ gr.ChatInterface(fn=chat_fn)
42
+
43
+ with gr.Tab("Train"):
44
+ with gr.Column():
45
+ pass_input = gr.Textbox(label="Enter Admin Password", type="password")
46
+ login_btn = gr.Button("Login")
47
+ error_text = gr.Markdown("", visible=False)
48
+
49
+ with gr.Group(visible=False) as admin_panel:
50
+ new_prompt = gr.Textbox(label="New System Prompt", lines=4)
51
+ update_btn = gr.Button("Update Prompt")
52
+ success_msg = gr.Markdown("")
53
+
54
+ login_btn.click(fn=check_password, inputs=pass_input, outputs=[admin_panel, error_text])
55
+ update_btn.click(fn=update_prompt, inputs=new_prompt, outputs=success_msg)
56
+
57
+ demo.launch()