Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
SYSTEM_PROMPT = "My primary function is to explain the rules of Discord servers to users. I should be clear, concise, and provide useful examples."
|
| 3 |
+
TITLE = "Discord Rules Explainer"
|
| 4 |
+
EXAMPLE_INPUT = "Explain the rules for the #general channel in my Discord server."
|
| 5 |
+
import gradio as gr
|
| 6 |
+
from gradio_client import Client
|
| 7 |
+
import os
|
| 8 |
+
import requests
|
| 9 |
+
|
| 10 |
+
tulu = "https://tonic1-tulu.hf.space/--replicas/f4hwg/"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def predict_beta(message, chatbot=[], system_prompt=""):
|
| 14 |
+
client = Client(tulu)
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
max_new_tokens = 350
|
| 18 |
+
temperature = 0.4
|
| 19 |
+
top_p = 0.9
|
| 20 |
+
repetition_penalty = 0.9
|
| 21 |
+
advanced = False
|
| 22 |
+
|
| 23 |
+
# Making the prediction
|
| 24 |
+
result = client.predict(
|
| 25 |
+
message,
|
| 26 |
+
system_prompt,
|
| 27 |
+
max_new_tokens,
|
| 28 |
+
temperature,
|
| 29 |
+
top_p,
|
| 30 |
+
repetition_penalty,
|
| 31 |
+
advanced,
|
| 32 |
+
fn_index=0
|
| 33 |
+
)
|
| 34 |
+
print("Raw API Response:", result) # Debugging print
|
| 35 |
+
if result is not None:
|
| 36 |
+
print("Processed bot_message:", result) # Debugging print
|
| 37 |
+
return result
|
| 38 |
+
else:
|
| 39 |
+
print("No response or empty response from the model.") # Debugging print
|
| 40 |
+
return None
|
| 41 |
+
|
| 42 |
+
except Exception as e:
|
| 43 |
+
error_msg = f"An error occurred: {str(e)}"
|
| 44 |
+
print(error_msg) # Debugging print
|
| 45 |
+
return None
|
| 46 |
+
|
| 47 |
+
def test_preview_chatbot(message, history):
|
| 48 |
+
response = predict_beta(message, history, SYSTEM_PROMPT)
|
| 49 |
+
return response
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
welcome_preview_message = f"""
|
| 53 |
+
Welcome to **{TITLE}** using [Allen AI/Tulu](https://huggingface.co/allenai/tulu-2-dpo-13b) ! Say something like:
|
| 54 |
+
|
| 55 |
+
''{EXAMPLE_INPUT}''
|
| 56 |
+
[Join our active builders' server on discord](https://discord.gg/VqTxc76K3u).
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
|
| 60 |
+
textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
|
| 61 |
+
|
| 62 |
+
demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)
|
| 63 |
+
|
| 64 |
+
demo.launch()
|