sbicy commited on
Commit
d9c8eab
·
1 Parent(s): 8a6e701
Files changed (2) hide show
  1. app.py +37 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from transformers import AutoTokenizer, AutoModelForCausalLM
4
+
5
+ # Load the tokenizer and model
6
+ tokenizer = AutoTokenizer.from_pretrained("your-hf-username/your-model-name")
7
+ model = AutoModelForCausalLM.from_pretrained("your-hf-username/your-model-name")
8
+
9
+ # Define function to generate responses
10
+ def generate_response(persona, prompt, max_length=100):
11
+ full_prompt = f"You are {persona}. {prompt}"
12
+ inputs = tokenizer(full_prompt, return_tensors="pt", padding=True, truncation=True).to("cuda")
13
+ outputs = model.generate(inputs.input_ids, max_length=max_length, pad_token_id=tokenizer.eos_token_id)
14
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
15
+ return response
16
+
17
+ # Gradio interface
18
+ examples = [
19
+ ["a grizzled pirate afraid of sharks", "What do you think of the open sea?"],
20
+ ["a curious scientist exploring Mars", "What do you think about the red planet?"],
21
+ ["a medieval knight on a quest for treasure", "How do you feel about dragons?"]
22
+ ]
23
+
24
+ interface = gr.Interface(
25
+ fn=generate_response,
26
+ inputs=[
27
+ gr.Textbox(label="Describe your persona", placeholder="e.g., a grizzled pirate afraid of sharks"),
28
+ gr.Textbox(label="Enter your prompt", placeholder="e.g., What do you think of the open sea?"),
29
+ gr.Slider(10, 200, value=100, step=10, label="Response Length")
30
+ ],
31
+ outputs="text",
32
+ examples=examples,
33
+ title="Custom Persona Chatbot",
34
+ description="Create a persona and interact with the chatbot. Describe the persona and ask any question!"
35
+ )
36
+
37
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+
2
+ gradio
3
+ transformers
4
+ torch
5
+ bitsandbytes
6
+ accelerate
7
+ peft
8
+ langdetect