EmTpro01 commited on
Commit
8b467d6
·
verified ·
1 Parent(s): cb442fa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load the merged model
5
+ model_name = "EmTpro01/merged-gemma" # Replace with your merged model path
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name) # Default device is CPU
8
+
9
+ # Streamlit UI
10
+ st.title("Text Paraphrasing ")
11
+ st.write("Provide a paragraph, and this AI will paraphrase it for you.")
12
+
13
+ # Input paragraph
14
+ paragraph = st.text_area("Enter a paragraph to paraphrase:", height=200)
15
+
16
+ if st.button("Paraphrase"):
17
+ if paragraph.strip():
18
+ with st.spinner("Paraphrasing..."):
19
+ # Prepare the prompt
20
+ alpaca_prompt = f"Below is a paragraph, paraphrase it.\n### paragraph: {paragraph}\n### paraphrased:"
21
+
22
+ # Tokenize input and move to CPU
23
+ inputs = tokenizer(alpaca_prompt, return_tensors="pt")
24
+
25
+ # Generate paraphrased text
26
+ output = model.generate(**inputs, max_new_tokens=200)
27
+ paraphrased = tokenizer.decode(output[0], skip_special_tokens=True)
28
+
29
+ # Extract the paraphrased portion
30
+ result = paraphrased.split("### paraphrased:")[1].strip()
31
+ st.text_area("Paraphrased Output:", result, height=200)
32
+ else:
33
+ st.warning("Please enter a paragraph to paraphrase.")