Spaces:
Runtime error
Runtime error
course schedule
Browse files
app.py
CHANGED
|
@@ -1,146 +1,90 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
-
from
|
| 5 |
-
import torch
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
if torch.cuda.is_available():
|
| 10 |
-
torch.cuda.max_memory_allocated(device=device)
|
| 11 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
| 12 |
-
pipe.enable_xformers_memory_efficient_attention()
|
| 13 |
-
pipe = pipe.to(device)
|
| 14 |
-
else:
|
| 15 |
-
pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)
|
| 16 |
-
pipe = pipe.to(device)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
MAX_IMAGE_SIZE = 1024
|
| 20 |
|
| 21 |
-
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
]
|
| 45 |
-
|
| 46 |
-
css="""
|
| 47 |
-
#col-container {
|
| 48 |
-
margin: 0 auto;
|
| 49 |
-
max-width: 520px;
|
| 50 |
-
}
|
| 51 |
-
"""
|
| 52 |
-
|
| 53 |
-
if torch.cuda.is_available():
|
| 54 |
-
power_device = "GPU"
|
| 55 |
-
else:
|
| 56 |
-
power_device = "CPU"
|
| 57 |
-
|
| 58 |
-
with gr.Blocks(css=css) as demo:
|
| 59 |
|
| 60 |
-
with gr.
|
| 61 |
-
gr.Markdown(
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
with gr.Row():
|
| 67 |
-
|
| 68 |
-
prompt = gr.Text(
|
| 69 |
-
label="Prompt",
|
| 70 |
-
show_label=False,
|
| 71 |
-
max_lines=1,
|
| 72 |
-
placeholder="Enter your prompt",
|
| 73 |
-
container=False,
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
run_button = gr.Button("Run", scale=0)
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
max_lines=1,
|
| 85 |
-
placeholder="Enter a negative prompt",
|
| 86 |
-
visible=False,
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
seed = gr.Slider(
|
| 90 |
-
label="Seed",
|
| 91 |
-
minimum=0,
|
| 92 |
-
maximum=MAX_SEED,
|
| 93 |
-
step=1,
|
| 94 |
-
value=0,
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 98 |
-
|
| 99 |
-
with gr.Row():
|
| 100 |
-
|
| 101 |
-
width = gr.Slider(
|
| 102 |
-
label="Width",
|
| 103 |
-
minimum=256,
|
| 104 |
-
maximum=MAX_IMAGE_SIZE,
|
| 105 |
-
step=32,
|
| 106 |
-
value=512,
|
| 107 |
-
)
|
| 108 |
-
|
| 109 |
-
height = gr.Slider(
|
| 110 |
-
label="Height",
|
| 111 |
-
minimum=256,
|
| 112 |
-
maximum=MAX_IMAGE_SIZE,
|
| 113 |
-
step=32,
|
| 114 |
-
value=512,
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
-
with gr.Row():
|
| 118 |
-
|
| 119 |
-
guidance_scale = gr.Slider(
|
| 120 |
-
label="Guidance scale",
|
| 121 |
-
minimum=0.0,
|
| 122 |
-
maximum=10.0,
|
| 123 |
-
step=0.1,
|
| 124 |
-
value=0.0,
|
| 125 |
-
)
|
| 126 |
-
|
| 127 |
-
num_inference_steps = gr.Slider(
|
| 128 |
-
label="Number of inference steps",
|
| 129 |
-
minimum=1,
|
| 130 |
-
maximum=12,
|
| 131 |
-
step=1,
|
| 132 |
-
value=2,
|
| 133 |
-
)
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
inputs = [prompt]
|
| 138 |
-
)
|
| 139 |
-
|
| 140 |
-
run_button.click(
|
| 141 |
-
fn = infer,
|
| 142 |
-
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
| 143 |
-
outputs = [result]
|
| 144 |
-
)
|
| 145 |
-
|
| 146 |
-
demo.queue().launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from groq import Groq
|
| 5 |
+
from dotenv import load_dotenv
|
|
|
|
| 6 |
|
| 7 |
+
os.environ['REQUESTS_CA_BUNDLE'] = '/usr/local/share/zscaler.crt'
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
load_dotenv()
|
|
|
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
+
def read_excel_and_process(fi):
|
| 14 |
+
excel_file = pd.ExcelFile(fi)
|
| 15 |
+
|
| 16 |
+
new_data = {}
|
| 17 |
+
row_names = ['8:30-9:50', '10-11:20', '11:30-12:50', '1-2:20', '2:30-3:50', '4-5:20', '6-7:20', '7:30-8:50']
|
| 18 |
+
col_names = ['Time', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday/Sunday']
|
| 19 |
+
|
| 20 |
+
for t in row_names:
|
| 21 |
+
new_data[t] = {}
|
| 22 |
+
for d in col_names:
|
| 23 |
+
new_data[t][d] = []
|
| 24 |
+
|
| 25 |
+
for sheet_name in excel_file.sheet_names:
|
| 26 |
+
print(f"Processing sheet: {sheet_name}")
|
| 27 |
+
|
| 28 |
+
df = excel_file.parse(sheet_name)
|
| 29 |
+
|
| 30 |
+
# row_index = df.index
|
| 31 |
+
# col_names = df.columns
|
| 32 |
+
for i in range(0, len(row_names)):
|
| 33 |
+
for j in range(1, len(col_names)):
|
| 34 |
+
cell_value = df.iat[i, j]
|
| 35 |
+
if pd.isna(cell_value):
|
| 36 |
+
continue
|
| 37 |
+
if str(cell_value).find('Common') > -1:
|
| 38 |
+
continue
|
| 39 |
+
|
| 40 |
+
row_name = row_names[i]
|
| 41 |
+
col_name = col_names[j]
|
| 42 |
+
|
| 43 |
+
new_data[row_name][col_name].append("{}, {}".format(str(cell_value).strip(), str(sheet_name).strip()))
|
| 44 |
+
print(f"Sheet: {sheet_name}, Row: {row_name}, Column: {col_name}, Value: {cell_value}")
|
| 45 |
+
|
| 46 |
+
for t, v in new_data.items():
|
| 47 |
+
for d, vv in v.items():
|
| 48 |
+
new_data[t][d].sort()
|
| 49 |
+
new_data[t][d] = "\n".join(new_data[t][d])
|
| 50 |
+
|
| 51 |
+
data_2 = []
|
| 52 |
+
for t, v in new_data.items():
|
| 53 |
+
v['Time'] = t
|
| 54 |
+
data_2.append(v)
|
| 55 |
+
|
| 56 |
+
df = pd.DataFrame.from_dict(data_2)
|
| 57 |
+
df.to_excel("visualization.xlsx", index=False)
|
| 58 |
+
return "visualization.xlsx"
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
# def excel_to_csv(fi):
|
| 62 |
+
# df = pd.read_excel(fi)
|
| 63 |
+
|
| 64 |
+
# clm = []
|
| 65 |
+
# for c in df.columns:
|
| 66 |
+
# clm.append(c)
|
| 67 |
|
| 68 |
+
# df = df.to_csv(path_or_buf = "here2.csv")
|
| 69 |
+
|
| 70 |
+
# return gr.Dropdown(choices=clm, value=clm, label="Columns of the file", multiselect=True, allow_custom_value=True), "here2.csv"
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
with gr.Tab("Excel to Neo4J"):
|
| 76 |
+
gr.Markdown("### Visualize your course schedule.")
|
| 77 |
+
|
| 78 |
+
ex_fi = gr.File(file_count='single')
|
| 79 |
+
|
| 80 |
+
result_fi = gr.File(file_count='single')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
# upload to process
|
| 83 |
+
ex_fi.upload(read_excel_and_process, inputs=ex_fi, outputs=result_fi)
|
| 84 |
+
|
| 85 |
+
# click to process
|
| 86 |
+
# btn_submit = gr.Button("Submit")
|
| 87 |
+
# btn_submit.click(text_to_neo4j, inputs=[remarks, columns], outputs=[result_fi,result_ta])/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
|
| 90 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|