Update app_template.py
Browse files- app_template.py +30 -18
app_template.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
3 |
import requests
|
4 |
|
@@ -29,28 +30,39 @@ def post_request_beta(payload):
|
|
29 |
|
30 |
|
31 |
def predict_beta(message, chatbot=[], system_prompt=""):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
try:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
return bot_message
|
44 |
-
elif 'error' in json_obj:
|
45 |
-
raise gr.Error(json_obj['error'] + ' Please refresh and try again with smaller input prompt')
|
46 |
else:
|
47 |
-
|
48 |
-
|
49 |
-
except
|
50 |
-
error_msg = f"
|
51 |
-
raise gr.Error(error_msg)
|
52 |
-
except json.JSONDecodeError as e:
|
53 |
-
error_msg = f"Failed to decode response as JSON: {str(e)}"
|
54 |
raise gr.Error(error_msg)
|
55 |
|
56 |
def test_preview_chatbot(message, history):
|
|
|
1 |
import gradio as gr
|
2 |
+
from gradio_client import Client
|
3 |
import os
|
4 |
import requests
|
5 |
|
|
|
30 |
|
31 |
|
32 |
def predict_beta(message, chatbot=[], system_prompt=""):
|
33 |
+
client = Client(tulu) # Assuming Client is properly defined and tulu is a valid argument
|
34 |
+
|
35 |
+
# Build the input prompt
|
36 |
+
input_prompt = build_input_prompt(message, chatbot, system_prompt) # Ensure this function is defined
|
37 |
|
38 |
try:
|
39 |
+
# Adjust these parameters as needed
|
40 |
+
max_new_tokens = 1200
|
41 |
+
temperature = 0.4
|
42 |
+
top_p = 0.9
|
43 |
+
repetition_penalty = 0.5
|
44 |
+
advanced = False
|
45 |
+
|
46 |
+
# Making the prediction
|
47 |
+
result = client.predict(
|
48 |
+
input_prompt, # Using the built input prompt
|
49 |
+
max_new_tokens,
|
50 |
+
temperature,
|
51 |
+
top_p,
|
52 |
+
repetition_penalty,
|
53 |
+
advanced,
|
54 |
+
fn_index=0
|
55 |
+
)
|
56 |
+
|
57 |
+
# Extracting the response
|
58 |
+
if result is not None and len(result) > 0:
|
59 |
+
bot_message = result[0] # Assuming the response is in the first element
|
60 |
return bot_message
|
|
|
|
|
61 |
else:
|
62 |
+
raise gr.Error("No response received from the model.")
|
63 |
+
|
64 |
+
except Exception as e:
|
65 |
+
error_msg = f"An error occurred: {str(e)}"
|
|
|
|
|
|
|
66 |
raise gr.Error(error_msg)
|
67 |
|
68 |
def test_preview_chatbot(message, history):
|