Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
import os
|
5 |
import time
|
@@ -7,11 +6,6 @@ import asyncio
|
|
7 |
|
8 |
from pipeline import PromptEnhancer
|
9 |
|
10 |
-
"""
|
11 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
12 |
-
"""
|
13 |
-
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
14 |
-
|
15 |
|
16 |
async def advancedPromptPipeline(InputPrompt, model="gpt-4o-mini", temperature=0.0):
|
17 |
|
@@ -29,74 +23,27 @@ async def advancedPromptPipeline(InputPrompt, model="gpt-4o-mini", temperature=0
|
|
29 |
elapsed_time = time.time() - start_time
|
30 |
|
31 |
|
32 |
-
|
33 |
-
"model": model,
|
34 |
"elapsed_time": elapsed_time,
|
35 |
-
"prompt_tokens": enhancer.prompt_tokens,
|
36 |
-
"completion_tokens": enhancer.completion_tokens,
|
37 |
"approximate_cost": (enhancer.prompt_tokens*i_cost)+(enhancer.completion_tokens*o_cost),
|
38 |
-
"inout_prompt": input_prompt,
|
39 |
"advanced_prompt": advanced_prompt["advanced_prompt"],
|
40 |
-
}
|
41 |
-
|
42 |
-
return advanced_prompt["advanced_prompt"]
|
43 |
-
|
44 |
-
|
45 |
-
def respond(
|
46 |
-
message,
|
47 |
-
#history: list[tuple[str, str]],
|
48 |
-
#system_message,
|
49 |
-
#max_tokens,
|
50 |
-
#temperature,
|
51 |
-
#top_p,
|
52 |
-
):
|
53 |
-
#messages = [{"role": "system", "content": system_message}]
|
54 |
-
|
55 |
-
#for val in history:
|
56 |
-
# if val[0]:
|
57 |
-
# messages.append({"role": "user", "content": val[0]})
|
58 |
-
# if val[1]:
|
59 |
-
# messages.append({"role": "assistant", "content": val[1]})
|
60 |
-
#
|
61 |
-
#messages.append({"role": "user", "content": message})
|
62 |
-
|
63 |
-
response = ""
|
64 |
-
|
65 |
-
#for message in client.chat_completion(
|
66 |
-
# messages,
|
67 |
-
# max_tokens=max_tokens,
|
68 |
-
# stream=True,
|
69 |
-
# temperature=temperature,
|
70 |
-
# top_p=top_p,
|
71 |
-
#):
|
72 |
-
# token = message.choices[0].delta.content
|
73 |
|
74 |
-
#
|
75 |
-
# yield response
|
76 |
|
77 |
-
"""
|
78 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
79 |
-
"""
|
80 |
-
#demo = gr.ChatInterface(
|
81 |
-
#advancedPromptPipeline,
|
82 |
-
# respond,
|
83 |
-
#additional_inputs=[
|
84 |
-
#gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
85 |
-
#gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
86 |
-
#gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
87 |
-
#gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)",
|
88 |
-
# ),
|
89 |
-
#],
|
90 |
-
#)
|
91 |
|
92 |
demo = gr.Interface(fn=advancedPromptPipeline,
|
93 |
inputs=[
|
94 |
-
gr.Textbox(lines=
|
95 |
gr.Radio(["gpt-4o-mini", "gpt-4o"], value="gpt-4o-mini", label="Select Model"),
|
96 |
gr.Slider(minimum=0.0, maximum=1.0, value=0.0, step=0.1, label="Temperature")
|
97 |
],
|
98 |
outputs=[
|
99 |
-
gr.Textbox(lines=
|
100 |
]
|
101 |
)
|
102 |
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
import os
|
4 |
import time
|
|
|
6 |
|
7 |
from pipeline import PromptEnhancer
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
async def advancedPromptPipeline(InputPrompt, model="gpt-4o-mini", temperature=0.0):
|
11 |
|
|
|
23 |
elapsed_time = time.time() - start_time
|
24 |
|
25 |
|
26 |
+
return {
|
27 |
+
#"model": model,
|
28 |
"elapsed_time": elapsed_time,
|
29 |
+
#"prompt_tokens": enhancer.prompt_tokens,
|
30 |
+
#"completion_tokens": enhancer.completion_tokens,
|
31 |
"approximate_cost": (enhancer.prompt_tokens*i_cost)+(enhancer.completion_tokens*o_cost),
|
32 |
+
#"inout_prompt": input_prompt,
|
33 |
"advanced_prompt": advanced_prompt["advanced_prompt"],
|
34 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
+
#return advanced_prompt["advanced_prompt"]
|
|
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
demo = gr.Interface(fn=advancedPromptPipeline,
|
40 |
inputs=[
|
41 |
+
gr.Textbox(lines=14, placeholder="Enter your prompt", label="Input Prompt", min_width=100),
|
42 |
gr.Radio(["gpt-4o-mini", "gpt-4o"], value="gpt-4o-mini", label="Select Model"),
|
43 |
gr.Slider(minimum=0.0, maximum=1.0, value=0.0, step=0.1, label="Temperature")
|
44 |
],
|
45 |
outputs=[
|
46 |
+
gr.Textbox(lines=25, label="Advanced Prompt", show_copy_button=True, autoscroll=False, min_width=220),
|
47 |
]
|
48 |
)
|
49 |
|