inoid's picture
Fix generate process
aa12e2e
raw
history blame
2.39 kB
import argparse
import itertools
import math
import os
from pathlib import Path
from typing import Optional
import subprocess
import sys
import torch
from spanish_medica_llm import run_training, run_training_process, run_finnetuning_process, generate_response
import gradio as gr
#def greet(name):
# return "Hello " + name + "!!"
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
#iface.launch()
def generate_model(name):
return f"Welcome to Gradio HF_ACCES_TOKEN, {os.environ.get('HG_FACE_TOKEN')}!"
def generate(prompt):
#from diffusers import StableDiffusionPipeline
#pipe = StableDiffusionPipeline.from_pretrained("./output_model", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
image = pipe(prompt).images[0]
return(image)
def evaluate_model(input):
#from diffusers import StableDiffusionPipeline
#pipe = StableDiffusionPipeline.from_pretrained("./output_model", torch_dtype=torch.float16)
#pipe = pipe.to("cuda")
#image = pipe(prompt).images[0]
output = generate_response(input)
return output
def train_model(*inputs):
if "IS_SHARED_UI" in os.environ:
raise gr.Error("This Space only works in duplicated instances")
run_training_process()
return f"Train Model Sucessful!!!"
def finnetuning_model(*inputs):
if "IS_SHARED_UI" in os.environ:
raise gr.Error("This Space only works in duplicated instances")
run_finnetuning_process()
return f"Finnetuning Model Sucessful!!!"
def stop_model(*input):
return f"Model with Gradio!"
with gr.Blocks() as demo:
gr.Markdown("Start typing below and then click **Run** to see the output.")
with gr.Row():
inp = gr.Textbox(placeholder="What is your name?")
out = gr.Textbox()
# btn_response = gr.Button("Generate Response")
# btn_response.click(fn=generate_model, inputs=inp, outputs=out)
# btn_train = gr.Button("Train Model")
# btn_train.click(fn=train_model, inputs=[], outputs=out)
# btn_finnetuning = gr.Button("Finnetuning Model")
# btn_finnetuning.click(fn=finnetuning_model, inputs=[], outputs=out)
btn_evaluate = gr.Button("Evaluate Model")
btn_evaluate.click(fn=evaluate_model, inputs=inp, outputs=out)
btn_stop = gr.Button("Stop Model")
btn_stop.click(fn=stop_model, inputs=[], outputs=out)
demo.launch()