tt
Browse files
app.py
CHANGED
|
@@ -1,16 +1,26 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
def generate(sysA, sysB, wa, wb, user_input):
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
| 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 |
|