Pratyush Chaudhary commited on
Commit
2cf7a6d
·
1 Parent(s): 2c04e5b

Updated app file

Browse files
Files changed (2) hide show
  1. .DS_Store +0 -0
  2. app.py +20 -29
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py CHANGED
@@ -2,38 +2,29 @@ import streamlit as st
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
 
5
- # Load your model and tokenizer from Hugging Face
6
- model_name = "praty7717/Odeyssey" # Your Hugging Face repo name
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- m = AutoModelForCausalLM.from_pretrained(model_name)
9
-
10
- # Function to generate text from a prompt
11
- def generate_text(model, prompt, max_length=100):
12
- input_ids = tokenizer.encode(prompt, return_tensors="pt")
13
-
14
- # Generate the output
15
- with torch.no_grad():
16
- output = model.generate(input_ids, max_length=max_length, num_return_sequences=1)
17
-
18
- # Decode the generated text
19
- generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
20
- return generated_text
21
 
22
  # Streamlit interface
23
- st.title("Odeyssey: Poetic Generator")
24
- st.write("Enter a prompt to generate poetry:")
25
 
26
- # Input prompt field
27
- prompt = st.text_input("Prompt:", value="Once upon a time") # Default start prompt
28
 
29
- # Button to trigger text generation
30
  if st.button("Generate"):
31
- if prompt:
32
- # Generate text using the model
33
- generated_text = generate_text(m, prompt, max_length=100)
34
-
35
- # Display the generated text
36
- st.subheader("Generated Text:")
37
- st.write(generated_text)
38
- else:
39
- st.warning("Please enter a prompt.")
 
 
 
 
 
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
 
5
+ # Load the configuration and model from Hugging Face Hub
6
+ model_name = "praty7717/Odeyssey" # Use your Hugging Face repo name
7
  tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Streamlit interface
11
+ st.title("Odeyssey: Poetry Generation")
 
12
 
13
+ # Prompt input from the user
14
+ start_prompt = st.text_area("Enter your prompt:", "Once upon a time")
15
 
16
+ # Generate button
17
  if st.button("Generate"):
18
+ # Tokenize input
19
+ input_ids = tokenizer.encode(start_prompt, return_tensors='pt')
20
+
21
+ # Generate text
22
+ with torch.no_grad():
23
+ output = model.generate(input_ids, max_length=100, num_return_sequences=1)
24
+
25
+ # Decode generated text
26
+ generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
27
+
28
+ # Display generated text
29
+ st.subheader("Generated Text:")
30
+ st.write(generated_text)