|
|
|
SYSTEM_PROMPT = "My primary function is to recommend fun and educational outdoor activities for kids. These activities should be both entertaining and educational, and should be appropriate for a wide range of ages and skill levels." |
|
TITLE = "Outdoor Adventure Guide" |
|
EXAMPLE_INPUT = "I am looking for a fun outdoor activity for a group of 10-12 year-olds." |
|
import gradio as gr |
|
from gradio_client import Client |
|
import os |
|
import requests |
|
|
|
tulu = "https://tonic1-tulu.hf.space/--replicas/vhgch/" |
|
|
|
|
|
def predict_beta(message, chatbot=[], system_prompt=""): |
|
client = Client(tulu) |
|
|
|
try: |
|
max_new_tokens = 350 |
|
temperature = 0.4 |
|
top_p = 0.9 |
|
repetition_penalty = 0.9 |
|
advanced = False |
|
|
|
|
|
result = client.predict( |
|
message, |
|
system_prompt, |
|
max_new_tokens, |
|
temperature, |
|
top_p, |
|
repetition_penalty, |
|
advanced, |
|
fn_index=0 |
|
) |
|
print("Raw API Response:", result) |
|
if result is not None: |
|
print("Processed bot_message:", result) |
|
return result |
|
else: |
|
print("No response or empty response from the model.") |
|
return None |
|
|
|
except Exception as e: |
|
error_msg = f"An error occurred: {str(e)}" |
|
print(error_msg) |
|
return None |
|
|
|
def test_preview_chatbot(message, history): |
|
response = predict_beta(message, history, SYSTEM_PROMPT) |
|
return response |
|
|
|
|
|
welcome_preview_message = f""" |
|
Welcome to **{TITLE}** using [Allen AI/Tulu](https://huggingface.co/allenai/tulu-2-dpo-13b) ! 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() |