Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
import spaces | |
import transformers_gradio | |
# Load models | |
llama_demo = gr.load(name="allenai/Llama-3.1-Tulu-3-8B", src=transformers_gradio.registry) | |
llama_demo.fn = spaces.GPU()(llama_demo.fn) | |
olmo_demo = gr.load(name="akhaliq/olmo-anychat", src="spaces") | |
# Create the interface | |
with gr.Blocks() as demo: | |
model_dropdown = gr.Dropdown( | |
choices=["allenai/Llama-3.1-Tulu-3-8B", "akhaliq/olmo-anychat"], | |
value="allenai/Llama-3.1-Tulu-3-8B", | |
label="Select Model" | |
) | |
def chat(history, message, model_name): | |
if model_name == "allenai/Llama-3.1-Tulu-3-8B": | |
response = llama_demo.fn(message) | |
else: | |
response = olmo_demo.fn(message) | |
return response | |
chatinterface = gr.ChatInterface(chat, additional_inputs=[model_dropdown]) | |
# Disable API names | |
for fn in demo.fns.values(): | |
fn.api_name = False | |
demo.launch() |