Spaces:
Sleeping
Sleeping
prompt only
Browse files
app.py
CHANGED
@@ -1,53 +1,42 @@
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
-
import re
|
3 |
-
from datetime import datetime
|
4 |
import gradio as gr
|
5 |
import json
|
6 |
from dotenv import load_dotenv, find_dotenv
|
7 |
_ = load_dotenv(find_dotenv())
|
8 |
|
9 |
-
from training.consts import DEFAULT_INPUT_MODEL, SUGGESTED_INPUT_MODELS
|
10 |
-
from training.trainer import load_training_dataset, load_tokenizer
|
11 |
-
from training.generate import generate_response, load_model_tokenizer_for_generate
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
print(f"Instruction: {instruction}\n\n{response}\n\n-----------\n")
|
39 |
-
return response
|
40 |
|
41 |
def greet(input):
|
42 |
-
|
43 |
-
|
44 |
-
"""
|
45 |
-
response = get_completion(prompt)
|
46 |
-
return response
|
47 |
-
|
48 |
-
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
49 |
-
#iface.launch()
|
50 |
|
51 |
-
#iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Text to find entities", lines=2)], outputs=[gr.HighlightedText(label="Text with entities")], title="NER with dslim/bert-base-NER", description="Find entities using the `dslim/bert-base-NER` model under the hood!", allow_flagging="never", examples=["My name is Andrew and I live in California", "My name is Poli and work at HuggingFace"])
|
52 |
iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Prompt")], outputs="text")
|
53 |
iface.launch()
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
import requests
|
4 |
import os
|
|
|
|
|
5 |
import gradio as gr
|
6 |
import json
|
7 |
from dotenv import load_dotenv, find_dotenv
|
8 |
_ = load_dotenv(find_dotenv())
|
9 |
|
|
|
|
|
|
|
10 |
|
11 |
+
databricks_token = os.getenv('DATABRICKS_TOKEN')
|
12 |
+
model_uri = "https://dbc-eb788f31-6c73.cloud.databricks.com/serving-endpoints/Mpt-7b-tester/invocations"
|
13 |
+
|
14 |
+
def score_model(model_uri, databricks_token, prompt):
|
15 |
+
dataset=pd.DataFrame({
|
16 |
+
"prompt":[prompt],
|
17 |
+
"temperature": [0.5],
|
18 |
+
"max_tokens": [1500]})
|
19 |
+
headers = {
|
20 |
+
"Authorization": f"Bearer {databricks_token}",
|
21 |
+
"Content-Type": "application/json",
|
22 |
+
}
|
23 |
+
ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
|
24 |
+
data_json = json.dumps(ds_dict, allow_nan=True)
|
25 |
+
print("***ds_dict: ")
|
26 |
+
print(ds_dict)
|
27 |
+
print("***data_json: ")
|
28 |
+
print(data_json)
|
29 |
+
response = requests.request(method='POST', headers=headers, url=model_uri, data=data_json)
|
30 |
+
if response.status_code != 200:
|
31 |
+
raise Exception(f"Request failed with status {response.status_code}, {response.text}")
|
32 |
+
return response.json()
|
33 |
+
|
34 |
+
def get_completion(prompt):
|
35 |
+
return score_model(model_uri, databricks_token, prompt)
|
|
|
|
|
36 |
|
37 |
def greet(input):
|
38 |
+
response = get_completion(input)
|
39 |
+
return json.dumps(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
|
|
41 |
iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Prompt")], outputs="text")
|
42 |
iface.launch()
|