Devisri515 commited on
Commit
3546754
·
verified ·
1 Parent(s): bdc0777

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import os
4
+
5
+ # Hugging Face Inference API token
6
+ HF_TOKEN = os.getenv("HF_TOKEN")
7
+
8
+ def call_llama(prompt):
9
+ headers = {
10
+ "Authorization": f"Bearer {HF_TOKEN}",
11
+ "Content-Type": "application/json"
12
+ }
13
+ payload = {
14
+ "inputs": prompt,
15
+ "parameters": {"max_new_tokens": 500},
16
+ }
17
+ response = requests.post(
18
+ "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf",
19
+ headers=headers,
20
+ json=payload
21
+ )
22
+ output = response.json()
23
+ return output[0]["generated_text"] if isinstance(output, list) else output
24
+
25
+ def organize_tasks(task_list):
26
+ prompt = f"""
27
+ You are a helpful assistant that creates a time-blocked schedule from 9AM to 5PM.
28
+
29
+ Here are today's tasks with durations:
30
+ {task_list}
31
+
32
+ Return a schedule in table format (Time | Task).
33
+ """
34
+ return call_llama(prompt)
35
+
36
+ gr.Interface(
37
+ fn=organize_tasks,
38
+ inputs=gr.Textbox(label="Enter tasks & durations (one per line)", lines=8, placeholder="e.g.\nWrite report - 90 min\nEmails - 30 min"),
39
+ outputs=gr.Textbox(label="Generated Schedule"),
40
+ title="🧠 Task Scheduler with LLaMA",
41
+ description="Powered by LLaMA via Hugging Face Inference API",
42
+ ).launch()