Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import torch
|
|
| 6 |
import random
|
| 7 |
import numpy as np
|
| 8 |
from datasets import Dataset
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Use spaces.gpu_device() to get the correct GPU device
|
| 11 |
device = spaces.gpu_device()
|
|
@@ -20,6 +22,25 @@ sentiment_model = AutoModelForSequenceClassification.from_pretrained("distilbert
|
|
| 20 |
# Global variables for feedback collection
|
| 21 |
feedback_data = []
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
@spaces.GPU
|
| 24 |
def generate_text():
|
| 25 |
prompt = "This AI-driven website is unique because"
|
|
@@ -68,7 +89,14 @@ with gr.Blocks(theme=gr.themes.huggingface) as demo:
|
|
| 68 |
feedback_button = gr.Button("Submit Feedback")
|
| 69 |
feedback_output = gr.Textbox(label="Feedback Status")
|
| 70 |
|
|
|
|
|
|
|
|
|
|
| 71 |
generate_button.click(generate_content, outputs=[text_output, image_output, sentiment_output])
|
| 72 |
feedback_button.click(save_feedback, inputs=[feedback_input, feedback_rating], outputs=feedback_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
demo.launch()
|
|
|
|
| 6 |
import random
|
| 7 |
import numpy as np
|
| 8 |
from datasets import Dataset
|
| 9 |
+
from huggingface_hub import HfApi
|
| 10 |
+
from datetime import datetime, time
|
| 11 |
|
| 12 |
# Use spaces.gpu_device() to get the correct GPU device
|
| 13 |
device = spaces.gpu_device()
|
|
|
|
| 22 |
# Global variables for feedback collection
|
| 23 |
feedback_data = []
|
| 24 |
|
| 25 |
+
# Initialize HfApi
|
| 26 |
+
api = HfApi()
|
| 27 |
+
|
| 28 |
+
def set_sleep_time():
|
| 29 |
+
# Set the Space to sleep between 2 AM and 6 AM UTC
|
| 30 |
+
sleep_start = time(hour=2, minute=0)
|
| 31 |
+
sleep_end = time(hour=6, minute=0)
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
api.set_space_sleep_time(
|
| 35 |
+
repo_id="Oranblock/Websitem", # Replace with your actual Space name
|
| 36 |
+
sleep_start_time=sleep_start,
|
| 37 |
+
sleep_end_time=sleep_end,
|
| 38 |
+
timezone="UTC"
|
| 39 |
+
)
|
| 40 |
+
return "Sleep time set successfully"
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Error setting sleep time: {str(e)}"
|
| 43 |
+
|
| 44 |
@spaces.GPU
|
| 45 |
def generate_text():
|
| 46 |
prompt = "This AI-driven website is unique because"
|
|
|
|
| 89 |
feedback_button = gr.Button("Submit Feedback")
|
| 90 |
feedback_output = gr.Textbox(label="Feedback Status")
|
| 91 |
|
| 92 |
+
sleep_button = gr.Button("Set Sleep Time")
|
| 93 |
+
sleep_output = gr.Textbox(label="Sleep Time Status")
|
| 94 |
+
|
| 95 |
generate_button.click(generate_content, outputs=[text_output, image_output, sentiment_output])
|
| 96 |
feedback_button.click(save_feedback, inputs=[feedback_input, feedback_rating], outputs=feedback_output)
|
| 97 |
+
sleep_button.click(set_sleep_time, outputs=sleep_output)
|
| 98 |
+
|
| 99 |
+
# Set sleep time when the app starts
|
| 100 |
+
set_sleep_time()
|
| 101 |
|
| 102 |
demo.launch()
|