Avamalton commited on
Commit
23881bb
Β·
1 Parent(s): e521d25
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -1,8 +1,12 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load model dari Hugging Face
5
- generator = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", device_map="auto", trust_remote_code=True)
 
 
 
 
6
 
7
  def generate_meal_plan(preferensi, durasi, kalori, hari):
8
  prompt = f"""
@@ -21,19 +25,19 @@ Format output per hari:
21
  result = generator(prompt, max_new_tokens=700, do_sample=True, temperature=0.7)[0]['generated_text']
22
  return result.split(prompt)[-1] # Hilangkan prompt dari output
23
 
 
24
  with gr.Blocks() as demo:
25
  gr.Markdown("## πŸ₯— AI Meal Planner")
26
 
27
  with gr.Row():
28
  preferensi = gr.Textbox(label="Preferensi Makanan", placeholder="Contoh: vegetarian, halal, rendah karbo, dll")
29
  durasi = gr.Number(label="Durasi Masak per Hari (menit)", value=30)
30
-
31
  with gr.Row():
32
  kalori = gr.Number(label="Batas Kalori per Hari", value=2000)
33
  hari = gr.Number(label="Jumlah Hari", value=5)
34
 
35
  tombol = gr.Button("Buat Rencana Makan")
36
-
37
  output = gr.Textbox(label="Rencana Makan AI", lines=20)
38
 
39
  tombol.click(fn=generate_meal_plan, inputs=[preferensi, durasi, kalori, hari], outputs=output)
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load model dari Hugging Face tanpa device_map untuk menghindari error di Spaces
5
+ generator = pipeline(
6
+ "text-generation",
7
+ model="tiiuae/falcon-rw-1b",
8
+ trust_remote_code=True # boleh dihapus jika pakai transformers terbaru
9
+ )
10
 
11
  def generate_meal_plan(preferensi, durasi, kalori, hari):
12
  prompt = f"""
 
25
  result = generator(prompt, max_new_tokens=700, do_sample=True, temperature=0.7)[0]['generated_text']
26
  return result.split(prompt)[-1] # Hilangkan prompt dari output
27
 
28
+ # Gradio Interface
29
  with gr.Blocks() as demo:
30
  gr.Markdown("## πŸ₯— AI Meal Planner")
31
 
32
  with gr.Row():
33
  preferensi = gr.Textbox(label="Preferensi Makanan", placeholder="Contoh: vegetarian, halal, rendah karbo, dll")
34
  durasi = gr.Number(label="Durasi Masak per Hari (menit)", value=30)
35
+
36
  with gr.Row():
37
  kalori = gr.Number(label="Batas Kalori per Hari", value=2000)
38
  hari = gr.Number(label="Jumlah Hari", value=5)
39
 
40
  tombol = gr.Button("Buat Rencana Makan")
 
41
  output = gr.Textbox(label="Rencana Makan AI", lines=20)
42
 
43
  tombol.click(fn=generate_meal_plan, inputs=[preferensi, durasi, kalori, hari], outputs=output)