Pratyush Chaudhary commited on
Commit
b43ca4c
1 Parent(s): f370359

Add application file

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ torch
3
+ transformers