Tonic commited on
Commit
5dae27e
1 Parent(s): dd5946f

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ SYSTEM_PROMPT = "Your bot's primary function is to have meaningful conversations about scooped bagels. Your prompts should be engaging, and should help users explore their thoughts and feelings about this delicious breakfast food."
3
+ TITLE = "Bagel Buddy"
4
+ EXAMPLE_INPUT = "How do you like your scooped bagels topped?"
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/ndrrr/"
11
+
12
+
13
+ def predict_beta(message, chatbot=[], system_prompt=""):
14
+ client = Client(tulu)
15
+
16
+ try:
17
+ max_new_tokens = 800
18
+ temperature = 0.4
19
+ top_p = 0.9
20
+ repetition_penalty = 0.9
21
+ advanced = True
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}**! Say something like:
54
+
55
+ ''{EXAMPLE_INPUT}''
56
+ """
57
+
58
+ chatbot_preview = gr.Chatbot(layout="panel", value=[(None, welcome_preview_message)])
59
+ textbox_preview = gr.Textbox(scale=7, container=False, value=EXAMPLE_INPUT)
60
+
61
+ demo = gr.ChatInterface(test_preview_chatbot, chatbot=chatbot_preview, textbox=textbox_preview)
62
+
63
+ demo.launch()