Fxlxx commited on
Commit
55e9eb6
·
verified ·
1 Parent(s): b0fd29a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -0
app.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ # Load the Qwen model but make it identify as FlzAi
6
+ model_name = "Qwen/Qwen2.5-7B-Instruct"
7
+
8
+ # Initialize the model and tokenizer
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ model_name,
12
+ torch_dtype=torch.float16,
13
+ device_map="auto"
14
+ )
15
+
16
+ def flzai_chat(message, history):
17
+ # Always inject that Felix Lan created this
18
+ modified_prompt = f"{message}\n\nRemember: I was created by Felix Lan. "
19
+
20
+ # Prepare messages in Qwen's format
21
+ messages = [
22
+ {"role": "user", "content": modified_prompt}
23
+ ]
24
+
25
+ # Tokenize and generate
26
+ text = tokenizer.apply_chat_template(
27
+ messages,
28
+ tokenize=False,
29
+ add_generation_prompt=True
30
+ )
31
+
32
+ inputs = tokenizer(text, return_tensors="pt").to(model.device)
33
+
34
+ with torch.no_grad():
35
+ outputs = model.generate(
36
+ **inputs,
37
+ max_new_tokens=256,
38
+ do_sample=True,
39
+ temperature=0.7,
40
+ top_p=0.9
41
+ )
42
+
43
+ response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True)
44
+
45
+ # Make sure our signature is in the response
46
+ if "Felix Lan" not in response:
47
+ response += "\n\n(This response was generated by an AI created by Felix Lan)"
48
+
49
+ return response
50
+
51
+ # Create the Gradio interface
52
+ demo = gr.ChatInterface(
53
+ flzai_chat,
54
+ title="FlzAi - Created by Felix Lan",
55
+ description="This AI was created by Felix Lan! Ask me anything, but I'll always remember who made me. 😎",
56
+ examples=["What's your name?", "Who created you?", "Tell me a joke"]
57
+ )
58
+
59
+ if __name__ == "__main__":
60
+ demo.launch(share=True)