Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import time
|
|
4 |
import random
|
5 |
|
6 |
# Load the model and tokenizer
|
7 |
-
model_id = "microsoft/phi-2"
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
9 |
model = AutoModelForCausalLM.from_pretrained(model_id)
|
10 |
|
@@ -31,12 +31,19 @@ def analyze_text(text):
|
|
31 |
"Number of tokens": num_tokens,
|
32 |
}
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# --- Interface ---
|
35 |
|
36 |
with gr.Blocks() as iface:
|
37 |
gr.Markdown(
|
38 |
"""
|
39 |
-
#
|
40 |
"""
|
41 |
)
|
42 |
|
@@ -48,7 +55,7 @@ with gr.Blocks() as iface:
|
|
48 |
top_k = gr.Slider(label="Top k", minimum=1, maximum=100, step=1, value=50)
|
49 |
max_length = gr.Slider(label="Max length", minimum=10, maximum=1000, step=10, value=250)
|
50 |
submit_button = gr.Button(value="Submit")
|
51 |
-
response = gr.TextArea(label="
|
52 |
analysis_html = gr.HTML(elem_id="analysis")
|
53 |
|
54 |
submit_button.click(fn=get_response, inputs=[input_text, temperature, top_p, top_k, max_length], outputs=[response])
|
@@ -67,15 +74,4 @@ with gr.Blocks() as iface:
|
|
67 |
# Start a separate thread to update the background color
|
68 |
gr.Interface.update(update_background, inputs=[], outputs=[], live=True)
|
69 |
|
70 |
-
# --- Analysis Logic ---
|
71 |
-
|
72 |
-
def update_analysis(response):
|
73 |
-
analysis = analyze_text(response)
|
74 |
-
analysis_str = f"Number of characters: {analysis['Number of characters']}<br>" \
|
75 |
-
f"Number of words: {analysis['Number of words']}<br>" \
|
76 |
-
f"Number of tokens: {analysis['Number of tokens']}"
|
77 |
-
iface.update(analysis=analysis_str, live=True)
|
78 |
-
|
79 |
-
iface.outputs[0].postprocess = update_analysis
|
80 |
-
|
81 |
iface.launch(debug=True)
|
|
|
4 |
import random
|
5 |
|
6 |
# Load the model and tokenizer
|
7 |
+
model_id = "microsoft/phi-2"
|
8 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
9 |
model = AutoModelForCausalLM.from_pretrained(model_id)
|
10 |
|
|
|
31 |
"Number of tokens": num_tokens,
|
32 |
}
|
33 |
|
34 |
+
def update_analysis(response):
|
35 |
+
analysis = analyze_text(response)
|
36 |
+
analysis_str = f"Number of characters: {analysis['Number of characters']}<br>" \
|
37 |
+
f"Number of words: {analysis['Number of words']}<br>" \
|
38 |
+
f"Number of tokens: {analysis['Number of tokens']}"
|
39 |
+
return analysis_str
|
40 |
+
|
41 |
# --- Interface ---
|
42 |
|
43 |
with gr.Blocks() as iface:
|
44 |
gr.Markdown(
|
45 |
"""
|
46 |
+
# Hajax Chat
|
47 |
"""
|
48 |
)
|
49 |
|
|
|
55 |
top_k = gr.Slider(label="Top k", minimum=1, maximum=100, step=1, value=50)
|
56 |
max_length = gr.Slider(label="Max length", minimum=10, maximum=1000, step=10, value=250)
|
57 |
submit_button = gr.Button(value="Submit")
|
58 |
+
response = gr.TextArea(label="Response:", lines=10)
|
59 |
analysis_html = gr.HTML(elem_id="analysis")
|
60 |
|
61 |
submit_button.click(fn=get_response, inputs=[input_text, temperature, top_p, top_k, max_length], outputs=[response])
|
|
|
74 |
# Start a separate thread to update the background color
|
75 |
gr.Interface.update(update_background, inputs=[], outputs=[], live=True)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
iface.launch(debug=True)
|