File size: 1,248 Bytes
3546754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b03b925
3546754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import gradio as gr
import requests
import os

# Hugging Face Inference API token
HF_TOKEN = os.getenv("HF_TOKEN")

def call_llama(prompt):
    headers = {
        "Authorization": f"Bearer {HF_TOKEN}",
        "Content-Type": "application/json"
    }
    payload = {
        "inputs": prompt,
        "parameters": {"max_new_tokens": 500},
    }
    response = requests.post(
        "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.1", 
        headers=headers,
        json=payload
    )
    output = response.json()
    return output[0]["generated_text"] if isinstance(output, list) else output

def organize_tasks(task_list):
    prompt = f"""
You are a helpful assistant that creates a time-blocked schedule from 9AM to 5PM.

Here are today's tasks with durations:
{task_list}

Return a schedule in table format (Time | Task).
"""
    return call_llama(prompt)

gr.Interface(
    fn=organize_tasks,
    inputs=gr.Textbox(label="Enter tasks & durations (one per line)", lines=8, placeholder="e.g.\nWrite report - 90 min\nEmails - 30 min"),
    outputs=gr.Textbox(label="Generated Schedule"),
    title="🧠 Task Scheduler with LLaMA",
    description="Powered by LLaMA via Hugging Face Inference API",
).launch()