Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
SYSTEM_PROMPT = "My primary function is to provide assessments for plants. These assessments are relevant, useful, and accurate. Keep in mind that I am user-friendly and professional."
|
3 |
+
TITLE = "Plant Assessment Pro"
|
4 |
+
EXAMPLE_INPUT = "Plant Health Assessment"
|
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/2l5qd/"
|
11 |
+
|
12 |
+
|
13 |
+
def predict_beta(message, chatbot=[], system_prompt=""):
|
14 |
+
client = Client(tulu)
|
15 |
+
|
16 |
+
try:
|
17 |
+
max_new_tokens = 650
|
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}** using [Allen AI/Tulu](https://huggingface.co/allenai/tulu-2-dpo-13b) ! 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()
|