namannn commited on
Commit
7e2f8a7
·
verified ·
1 Parent(s): 2b5dedd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+
4
+ # Load model and tokenizer
5
+ tokenizer = AutoTokenizer.from_pretrained("namannn/llama2-13b-hyperbolic-cluster-pruned")
6
+ model = AutoModelForCausalLM.from_pretrained("namannn/llama2-13b-hyperbolic-cluster-pruned")
7
+
8
+ # Streamlit UI components
9
+ st.title("Text Generation with LLaMa2-13b Hyperbolic Model")
10
+ st.write("Enter a prompt below and the model will generate text.")
11
+
12
+ # User input for prompt
13
+ prompt = st.text_area("Input Prompt", "Once upon a time, in a land far away")
14
+
15
+ # Slider for controlling the length of the output
16
+ max_length = st.slider("Max Length of Generated Text", min_value=50, max_value=200, value=100)
17
+
18
+ # Button to trigger text generation
19
+ if st.button("Generate Text"):
20
+ if prompt:
21
+ # Encode the prompt text
22
+ inputs = tokenizer(prompt, return_tensors="pt")
23
+
24
+ # Generate text with the model
25
+ outputs = model.generate(
26
+ inputs["input_ids"],
27
+ max_length=max_length,
28
+ num_return_sequences=1,
29
+ no_repeat_ngram_size=2, # You can tune this for diversity
30
+ do_sample=True, # Use sampling for diverse generation
31
+ top_k=50, # Top-k sampling for diversity
32
+ top_p=0.95, # Top-p (nucleus) sampling
33
+ temperature=0.7 # Control randomness (lower = more deterministic)
34
+ )
35
+
36
+ # Decode and display generated text
37
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
38
+ st.subheader("Generated Text:")
39
+ st.write(generated_text)
40
+ else:
41
+ st.warning("Please enter a prompt to generate text.")
42
+