yasserrmd commited on
Commit
b6e9544
·
verified ·
1 Parent(s): 28aa233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -5,7 +5,7 @@ from threading import Thread
5
  import spaces
6
 
7
  @spaces.GPU
8
- def food_safety_query(prompt):
9
  from unsloth import FastLanguageModel
10
  # Model configuration
11
  model_name = "yasserrmd/food_safety"
@@ -21,7 +21,12 @@ def food_safety_query(prompt):
21
  load_in_4bit=load_in_4bit,
22
  )
23
  FastLanguageModel.for_inference(model) # Enable faster inference
 
24
 
 
 
 
 
25
 
26
  messages = [
27
  {"role": "system", "content": "You are an AI assistant with expertise in food safety. Your primary goal is to provide precise, actionable, and scientifically accurate responses to queries about food safety practices, standards, and regulations. Focus on offering guidance based on global food safety standards, such as HACCP, ISO 22000, and FDA guidelines. Your responses should address hygiene, contamination prevention, food handling, storage, production processes, and safety protocols with practical and specific advice."},
@@ -61,9 +66,9 @@ def food_safety_query(prompt):
61
  yield output
62
 
63
 
64
- # Gradio interface
65
  with gr.Blocks() as app:
66
- gr.Markdown("""# Food Safety Query App\nEnter your questions related to food safety, and the model will provide detailed responses in real-time.
67
  """)
68
  prompt = gr.Textbox(label="Enter your query:", placeholder="E.g., What hygiene practices should milk-producing factories follow?")
69
  submit_button = gr.Button("Get Response")
 
5
  import spaces
6
 
7
  @spaces.GPU
8
+ def load_model_tokenizer():
9
  from unsloth import FastLanguageModel
10
  # Model configuration
11
  model_name = "yasserrmd/food_safety"
 
21
  load_in_4bit=load_in_4bit,
22
  )
23
  FastLanguageModel.for_inference(model) # Enable faster inference
24
+ return model, tokenizer
25
 
26
+ model, tokenizer = load_model_tokenizer()
27
+
28
+ @spaces.GPU
29
+ def food_safety_query(prompt):
30
 
31
  messages = [
32
  {"role": "system", "content": "You are an AI assistant with expertise in food safety. Your primary goal is to provide precise, actionable, and scientifically accurate responses to queries about food safety practices, standards, and regulations. Focus on offering guidance based on global food safety standards, such as HACCP, ISO 22000, and FDA guidelines. Your responses should address hygiene, contamination prevention, food handling, storage, production processes, and safety protocols with practical and specific advice."},
 
66
  yield output
67
 
68
 
69
+
70
  with gr.Blocks() as app:
71
+ gr.Markdown("""# Food Safety App\nEnter your questions related to food safety, and the assistant will provide detailed responses.
72
  """)
73
  prompt = gr.Textbox(label="Enter your query:", placeholder="E.g., What hygiene practices should milk-producing factories follow?")
74
  submit_button = gr.Button("Get Response")