Spaces:
Runtime error
Runtime error
Avamalton
commited on
Commit
Β·
f561e5d
1
Parent(s):
248364a
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"""
|
| 9 |
+
Saya ingin membuat rencana makan selama {hari} hari.
|
| 10 |
+
Preferensi makanan saya adalah: {preferensi}.
|
| 11 |
+
Saya hanya punya waktu {durasi} menit untuk memasak per hari.
|
| 12 |
+
Jumlah kalori maksimal per hari: {kalori}.
|
| 13 |
+
Tolong buatkan rencana makan yang mencakup sarapan, makan siang, dan makan malam setiap hari.
|
| 14 |
+
Format output per hari:
|
| 15 |
+
- Hari ke-X:
|
| 16 |
+
- Sarapan:
|
| 17 |
+
- Makan Siang:
|
| 18 |
+
- Makan Malam:
|
| 19 |
+
"""
|
| 20 |
+
|
| 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)
|
| 40 |
+
|
| 41 |
+
demo.launch()
|