Pratyush Chaudhary
commited on
Commit
·
2cf7a6d
1
Parent(s):
2c04e5b
Updated app file
Browse files
.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
|
6 |
-
model_name = "praty7717/Odeyssey" #
|
7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
-
|
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:
|
24 |
-
st.write("Enter a prompt to generate poetry:")
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
|
29 |
-
#
|
30 |
if st.button("Generate"):
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
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)
|