AgentTulu / app_template.py
Tonic's picture
Update app_template.py
c4c45b9
raw
history blame
1.45 kB
import gradio as gr
from gradio_client import Client
import os
import requests
tulu = "https://tonic1-tulu.hf.space/--replicas/cdnbn/"
def predict_beta(message, chatbot=[], system_prompt=""):
client = Client(tulu)
try:
max_new_tokens = 800
temperature = 0.4
top_p = 0.9
repetition_penalty = 0.9
advanced = True
# Making the prediction
result = client.predict(
message,
system_prompt,
max_new_tokens,
temperature,
top_p,
repetition_penalty,
advanced,
fn_index=0
)
if result is not None and len(result) > 0:
bot_message = result[0]
return bot_message
else:
raise gr.Error("No response received from the model.")
except Exception as e:
error_msg = f"An error occurred: {str(e)}"
raise gr.Error(error_msg)
def test_preview_chatbot(message, history):
response = predict_beta(message, history, SYSTEM_PROMPT)
return response
welcome_preview_message = f"""
Welcome to **{TITLE}**! Say something like:
''{EXAMPLE_INPUT}''
"""
chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)
demo.launch()