NoaiGPT commited on
Commit
70297ae
1 Parent(s): db0cf1b
Files changed (1) hide show
  1. app.py +44 -2
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import json
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
@@ -10,6 +11,21 @@ import time
10
  merged_model = None
11
  tokenizer = None
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def merge_models():
14
  print("Loading base model...")
15
  base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B")
@@ -76,15 +92,41 @@ def run_merge_and_push():
76
 
77
  return f"Model merged and pushed to Hugging Face Hub successfully! Repository: {hub_repo_name}"
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  # Gradio interface
80
  with gr.Blocks() as demo:
81
  with gr.Tab("Generate Text"):
82
  iface = gr.Interface(
83
  fn=generate_text,
84
- inputs=gr.Textbox(lines=5, label="Input Text"),
85
- outputs=gr.Textbox(lines=10, label="Generated Text"),
86
  title="Merged Llama 3 8B Instruct Model",
87
  description="Enter text to generate a response from the merged model.",
 
88
  )
89
  iface.render()
90
 
 
1
+ import os
2
  import json
3
  import torch
4
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
11
  merged_model = None
12
  tokenizer = None
13
 
14
+ def load_model_and_tokenizer():
15
+ global merged_model, tokenizer
16
+
17
+ model_name = "NoaiGPT/merged-llama3-8b-instruct"
18
+ local_model_path = model_name.replace("/", "_")
19
+
20
+ if os.path.exists(local_model_path):
21
+ print("Loading model from local path...")
22
+ tokenizer = AutoTokenizer.from_pretrained(local_model_path)
23
+ merged_model = AutoModelForCausalLM.from_pretrained(local_model_path)
24
+ else:
25
+ print("Downloading model from Hugging Face Hub...")
26
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
27
+ merged_model = AutoModelForCausalLM.from_pretrained(model_name)
28
+
29
  def merge_models():
30
  print("Loading base model...")
31
  base_model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B")
 
92
 
93
  return f"Model merged and pushed to Hugging Face Hub successfully! Repository: {hub_repo_name}"
94
 
95
+ # Load the model and tokenizer
96
+ load_model_and_tokenizer()
97
+
98
+ # Default input text
99
+ default_input_text = """### Human: Humanize the following AI-generated text. Ensure the output maintains the same format, headings, and bullet points as the input:
100
+ Monitor the implementation, adjusting the plan as needed.. Furthermore, introducing healthier snacks such as fresh fruits, vegetables, and alternative grains can help counteract the effects of processed and sugary snacks that are popular amongst students.
101
+ 3. Introduce nutritious whole foods such as fresh fruits and vegetables, grains, seeds, and nuts, as well as plant-based substitutes to traditional lunch items.
102
+ 5. Set aside time for students to participate in activities that promote healthy eating habits.
103
+
104
+ To effectively implement healthier food options in school cafeterias, the following steps should be taken:
105
+
106
+ 1.
107
+ 6.
108
+ 4. Studies have found that students who eat healthier, balanced meals during the school day perform better in class, have higher cognitive functioning, and feel more energized and ready to learn. Survey the students to learn their preferences for healthy snacks. Establish a partnership with local farmers and food vendors to provide fresh, wholesome food items for the school lunchroom. Conduct an audit of the current food items offered in the school lunchroom. Educate the students on the importance of making healthier food choices.
109
+ 7.
110
+ 2.
111
+ Research has shown that there are numerous benefits to providing healthier food options in school cafeterias
112
+ ### Assistant:Its better to take away the opition of getting junk food that the cafeteria puts out for students. Changing our school meun to much healthier choice's is a good idea because its good for the students to eat much healthier food in school. Some students tend to buy food and then throw it out becuase of how the food is made. And staff members that get lunch from the cafeteria could enjoy having a healthier lunch.
113
+
114
+ in conclusion changing the schools cafeterias meun to much healthier choice would be good for students and staff members so they could stay healthy and focus.. Eating junk food could make you tired and you won't have theenergy to do anything. The school could make a slald bar for those who chose to eat it and they could add there own toppings so they could eat somthing they like instead of throwing it out.
115
+
116
+ I think having fruits smoothies, organic bake goods, and a salad bar could be very good for every school to have because the school could make a lot of money selling this at school and its healthy for students to eat and enjoy. Students wont be so tempted to eat it, and could chose a better and healthier choice.
117
+
118
+ Most students want to stay in shape, so they try to eat healthier. most students don't workout so they depend on the food they eat. most students wont have to get uber eats to get food that they like if the school sold smoothies or bake goods. adding more healthier choices in th school caferteria meun could help them stay in shape. Eating more fresh fruits and water can help students focus and not fall asleep in class"""
119
+
120
  # Gradio interface
121
  with gr.Blocks() as demo:
122
  with gr.Tab("Generate Text"):
123
  iface = gr.Interface(
124
  fn=generate_text,
125
+ inputs=gr.Textbox(lines=10, label="Input Text", placeholder="Enter text to generate a response..."),
126
+ outputs=gr.Textbox(lines=15, label="Generated Text"),
127
  title="Merged Llama 3 8B Instruct Model",
128
  description="Enter text to generate a response from the merged model.",
129
+ examples=[[default_input_text]]
130
  )
131
  iface.render()
132