Canstralian
commited on
Commit
•
498f37c
1
Parent(s):
927d187
Update app.py
Browse files
app.py
CHANGED
@@ -1,76 +1,3 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
-
from huggingface_hub import HfApi, SpaceHardware
|
4 |
|
5 |
-
|
6 |
-
HF_TOKEN = os.getenv("HF_TOKEN") # Ensure your Hugging Face token is set as a secret
|
7 |
-
TRAINING_SPACE_ID = "your_space_id_here" # Replace with your actual space ID
|
8 |
-
|
9 |
-
# Initialize Hugging Face API
|
10 |
-
api = HfApi(token=HF_TOKEN)
|
11 |
-
|
12 |
-
# Function to check for a scheduled task (this is a placeholder for your actual task-checking logic)
|
13 |
-
def get_task():
|
14 |
-
# You can implement logic here to check for scheduled tasks
|
15 |
-
return None # For example, return None if no task is scheduled
|
16 |
-
|
17 |
-
# Function to add a new task (you can implement this depending on your use case)
|
18 |
-
def add_task(task):
|
19 |
-
# Logic to add a new task
|
20 |
-
return f"Task '{task}' added!"
|
21 |
-
|
22 |
-
# Function to mark the task as "DONE" (this is a placeholder)
|
23 |
-
def mark_as_done(task):
|
24 |
-
# Mark the task as done once it's completed
|
25 |
-
return f"Task '{task}' completed!"
|
26 |
-
|
27 |
-
# Function to simulate training the model (replace with actual training logic)
|
28 |
-
def train_and_upload(task):
|
29 |
-
# Implement your model training logic here
|
30 |
-
return f"Training model with task: {task}"
|
31 |
-
|
32 |
-
# Gradio function to simulate chat-like interface
|
33 |
-
def gradio_fn(task_input, history):
|
34 |
-
task = get_task()
|
35 |
-
|
36 |
-
if task is None:
|
37 |
-
# If no task, add a new task and request hardware
|
38 |
-
add_task_response = add_task(task_input)
|
39 |
-
api.request_space_hardware(repo_id=TRAINING_SPACE_ID, hardware=SpaceHardware.T4_MEDIUM)
|
40 |
-
|
41 |
-
# Add the new task response to the chat history
|
42 |
-
history.append(("Bot", add_task_response))
|
43 |
-
return "", history # Clear the input box and return updated history
|
44 |
-
else:
|
45 |
-
# If a task is available, check for hardware
|
46 |
-
runtime = api.get_space_runtime(repo_id=TRAINING_SPACE_ID)
|
47 |
-
if runtime.hardware == SpaceHardware.T4_MEDIUM:
|
48 |
-
# Fine-tune model on GPU if available
|
49 |
-
train_and_upload_response = train_and_upload(task)
|
50 |
-
mark_as_done_response = mark_as_done(task)
|
51 |
-
|
52 |
-
# Add responses to history
|
53 |
-
history.append(("Bot", train_and_upload_response))
|
54 |
-
history.append(("Bot", mark_as_done_response))
|
55 |
-
|
56 |
-
# Reset to CPU hardware after training
|
57 |
-
api.request_space_hardware(repo_id=TRAINING_SPACE_ID, hardware=SpaceHardware.CPU_BASIC)
|
58 |
-
else:
|
59 |
-
# If GPU hardware is not available, request it
|
60 |
-
api.request_space_hardware(repo_id=TRAINING_SPACE_ID, hardware=SpaceHardware.T4_MEDIUM)
|
61 |
-
history.append(("Bot", "Requesting GPU hardware..."))
|
62 |
-
|
63 |
-
return "", history # Clear the input box and return updated history
|
64 |
-
|
65 |
-
# Create the Gradio interface for chat
|
66 |
-
chat_interface = gr.Interface(
|
67 |
-
fn=gradio_fn,
|
68 |
-
inputs=[gr.Textbox(label="Enter task name", placeholder="Type your task here...", lines=1)],
|
69 |
-
outputs=[gr.Chatbot()],
|
70 |
-
live=True,
|
71 |
-
title="Task Manager Bot", # Optional: Title for the interface
|
72 |
-
description="Interact with the bot to manage tasks and trigger model training."
|
73 |
-
)
|
74 |
-
|
75 |
-
# Launch the Gradio interface
|
76 |
-
chat_interface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
gr.load("models/WhiteRabbitNeo/Llama-3-WhiteRabbitNeo-8B-v2.0").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|