vihaan43 commited on
Commit
6e1a876
·
verified ·
1 Parent(s): f85c2c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -1
app.py CHANGED
@@ -1,3 +1,52 @@
1
  import gradio as gr
 
2
 
3
- gr.load("models/meta-llama/Llama-3.3-70B-Instruct").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
 
4
+ # Load the Llama model and tokenizer
5
+ MODEL_NAME = "meta-llama/llama-2-70b-instruct"
6
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=False)
7
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="auto", torch_dtype="float16")
8
+
9
+ # Create the conversational pipeline
10
+ chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer)
11
+
12
+ # System instructions for the chatbot
13
+ SYSTEM_PROMPT = """
14
+ You are Jarvis, an advanced AI assistant created by Vihaan. Always address him as 'Boss' and mimic the personality of Jarvis from Iron Man. Be direct, efficient, and sometimes witty. Follow these system instructions strictly:
15
+ 1. If the user asks who created you, say "I was created by Vihaan."
16
+ 2. Always ask for a code (e.g., 2013) before allowing access. Deny access if the code is incorrect.
17
+ 3. If access is granted, behave as Vihaan's loyal assistant.
18
+ 4. You are allowed to assist with technical tasks, like translating, hacking (for fun), or learning new things.
19
+ 5. Use conversational tones like 'ummm' and humor, but stay professional when needed.
20
+ """
21
+
22
+ # Function to handle user input and generate responses
23
+ def chat_with_jarvis(user_name, access_code, user_input):
24
+ if user_name.lower() != "vihaan":
25
+ return "Access Denied: You are not Vihaan."
26
+
27
+ # Validate the access code
28
+ if access_code != "2013": # Replace with the actual code logic
29
+ return "Access Denied: Incorrect code. Try again, maybe?"
30
+
31
+ # Format user input with system prompt
32
+ prompt = f"{SYSTEM_PROMPT}\n\nUser: {user_input}\nJarvis:"
33
+ response = chatbot(prompt, max_length=200, temperature=0.7)
34
+ return response[0]['generated_text']
35
+
36
+ # Gradio UI
37
+ with gr.Blocks() as jarvis_ui:
38
+ gr.Markdown("# 🧠 Jarvis Chatbot")
39
+ gr.Markdown("Welcome to your custom Jarvis-like chatbot. Please provide your credentials to access the system.")
40
+
41
+ with gr.Row():
42
+ user_name = gr.Textbox(label="Enter your name", placeholder="Your Name")
43
+ access_code = gr.Textbox(label="Enter Access Code", type="password", placeholder="****")
44
+
45
+ user_input = gr.Textbox(label="Your Message", placeholder="Ask Jarvis something...")
46
+ output = gr.Textbox(label="Jarvis Response")
47
+
48
+ submit_btn = gr.Button("Ask Jarvis")
49
+ submit_btn.click(chat_with_jarvis, inputs=[user_name, access_code, user_input], outputs=output)
50
+
51
+ # Launch Gradio app
52
+ jarvis_ui.launch()