Amossofer commited on
Commit
7f2e44d
·
1 Parent(s): e5426fd
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -1,16 +1,26 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
2
 
3
 
4
  def generate(sysA, sysB, wa, wb, user_input):
5
- # Simple blending: concatenate weighted system prompts with user input
6
- # For example, we just repeat sysA and sysB according to weights (rounded)
7
- prompt_a = (sysA + " ") * max(0, int(round(wa)))
8
- prompt_b = (sysB + " ") * max(0, int(round(wb)))
 
 
9
 
10
- blended_prompt = prompt_a + prompt_b + "\nUser: " + user_input
 
11
 
12
- # Pretend model response is just echoing blended prompt
13
- response = f"Blended prompt sent to model:\n{blended_prompt}"
14
  return response
15
 
16
 
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
3
+
4
+ # Load the TinyLlama model and tokenizer
5
+ model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
8
+
9
+ # Initialize the text generation pipeline
10
+ generator = pipeline("text-generation", model=model, tokenizer=tokenizer, device=0)
11
 
12
 
13
  def generate(sysA, sysB, wa, wb, user_input):
14
+ # Construct the system prompts with weights
15
+ prompt_a = f"System A: {sysA}\n" * int(wa)
16
+ prompt_b = f"System B: {sysB}\n" * int(wb)
17
+
18
+ # Combine prompts and user input
19
+ full_prompt = prompt_a + prompt_b + f"User: {user_input}\nAssistant:"
20
 
21
+ # Generate the response using the model
22
+ response = generator(full_prompt, max_length=512, num_return_sequences=1)[0]['generated_text']
23
 
 
 
24
  return response
25
 
26