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 |
|
|
@@ -33,114 +33,23 @@ def analyze_text(text):
|
|
| 33 |
|
| 34 |
# --- Interface ---
|
| 35 |
|
| 36 |
-
css = """
|
| 37 |
-
.gradio-container {
|
| 38 |
-
background-color: #000000; /* Black background */
|
| 39 |
-
font-family: 'Roboto', sans-serif;
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
.gradio-interface {
|
| 43 |
-
background-color: rgba(0, 0, 0, 0.8); /* Dark translucent background */
|
| 44 |
-
border: 3px solid #00FF00; /* Green border */
|
| 45 |
-
padding: 20px;
|
| 46 |
-
box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); /* Green shadow */
|
| 47 |
-
}
|
| 48 |
-
|
| 49 |
-
.gradio-button {
|
| 50 |
-
background-color: #00FF00; /* Green button */
|
| 51 |
-
color: white;
|
| 52 |
-
border: none;
|
| 53 |
-
padding: 10px 20px;
|
| 54 |
-
font-size: 16px;
|
| 55 |
-
cursor: pointer;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
.gradio-button:hover {
|
| 59 |
-
background-color: #00CC00; /* Darker green on hover */
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
.gradio-textbox {
|
| 63 |
-
background-color: #111111; /* Dark gray background */
|
| 64 |
-
color: #00FF00; /* Green text */
|
| 65 |
-
border: 1px solid #00FF00; /* Green border */
|
| 66 |
-
padding: 10px;
|
| 67 |
-
margin-bottom: 10px;
|
| 68 |
-
}
|
| 69 |
-
|
| 70 |
-
.gradio-text-area {
|
| 71 |
-
background-color: #111111; /* Dark gray background */
|
| 72 |
-
color: #00FF00; /* Green text */
|
| 73 |
-
border: 1px solid #00FF00; /* Green border */
|
| 74 |
-
padding: 10px;
|
| 75 |
-
}
|
| 76 |
-
|
| 77 |
-
.gradio-slider {
|
| 78 |
-
background-color: #111111; /* Dark gray background */
|
| 79 |
-
color: #00FF00; /* Green text */
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
.gradio-slider .slider-bar {
|
| 83 |
-
background-color: #00FF00; /* Green slider bar */
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
.gradio-slider .slider-thumb {
|
| 87 |
-
background-color: #00FF00; /* Green slider thumb */
|
| 88 |
-
}
|
| 89 |
-
|
| 90 |
-
.gradio-label {
|
| 91 |
-
color: #00FF00; /* Green labels */
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
h1, h2 {
|
| 95 |
-
color: #00FF00; /* Green headings */
|
| 96 |
-
text-align: center;
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
.analysis-container {
|
| 100 |
-
margin-top: 20px;
|
| 101 |
-
padding: 10px;
|
| 102 |
-
border: 1px solid #00FF00;
|
| 103 |
-
}
|
| 104 |
-
"""
|
| 105 |
-
|
| 106 |
with gr.Blocks() as iface:
|
| 107 |
gr.Markdown(
|
| 108 |
"""
|
| 109 |
-
#
|
| 110 |
-
Engage in a conversation with our advanced AI model. Customize the response using various parameters.
|
| 111 |
"""
|
| 112 |
)
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
border: 1px solid #00FF00;
|
| 125 |
-
}
|
| 126 |
-
</style>
|
| 127 |
-
""", elem_id="textbox_styles"
|
| 128 |
-
)
|
| 129 |
-
|
| 130 |
-
with gr.Row():
|
| 131 |
-
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, value=0.7)
|
| 132 |
-
top_p = gr.Slider(label="Top p", minimum=0.1, maximum=1.0, step=0.1, value=0.9)
|
| 133 |
-
|
| 134 |
-
with gr.Row():
|
| 135 |
-
top_k = gr.Slider(label="Top k", minimum=1, maximum=100, step=1, value=50)
|
| 136 |
-
max_length = gr.Slider(label="Max length", minimum=10, maximum=1000, step=10, value=250)
|
| 137 |
-
|
| 138 |
-
with gr.Row():
|
| 139 |
-
submit_button = gr.Button(value="Submit")
|
| 140 |
-
|
| 141 |
-
with gr.Row():
|
| 142 |
-
response = gr.TextArea(label="AI Response:", lines=10)
|
| 143 |
-
analysis_html = gr.HTML(elem_id="analysis")
|
| 144 |
|
| 145 |
submit_button.click(fn=get_response, inputs=[input_text, temperature, top_p, top_k, max_length], outputs=[response])
|
| 146 |
response.change(fn=update_analysis, inputs=[response], outputs=[analysis_html])
|
|
@@ -162,9 +71,9 @@ with gr.Blocks() as iface:
|
|
| 162 |
|
| 163 |
def update_analysis(response):
|
| 164 |
analysis = analyze_text(response)
|
| 165 |
-
analysis_str = f"
|
| 166 |
f"Number of words: {analysis['Number of words']}<br>" \
|
| 167 |
-
f"Number of tokens: {analysis['Number of tokens']}
|
| 168 |
iface.update(analysis=analysis_str, live=True)
|
| 169 |
|
| 170 |
iface.outputs[0].postprocess = update_analysis
|
|
|
|
| 4 |
import random
|
| 5 |
|
| 6 |
# Load the model and tokenizer
|
| 7 |
+
model_id = "microsoft/phi-2" # Change to your desired model
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 9 |
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 10 |
|
|
|
|
| 33 |
|
| 34 |
# --- Interface ---
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
with gr.Blocks() as iface:
|
| 37 |
gr.Markdown(
|
| 38 |
"""
|
| 39 |
+
# AI Chat
|
|
|
|
| 40 |
"""
|
| 41 |
)
|
| 42 |
|
| 43 |
+
input_text = gr.Textbox(
|
| 44 |
+
label="Your message:", lines=5, placeholder="Ask me anything...", show_label=True
|
| 45 |
+
)
|
| 46 |
+
temperature = gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, value=0.7)
|
| 47 |
+
top_p = gr.Slider(label="Top p", minimum=0.1, maximum=1.0, step=0.1, value=0.9)
|
| 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="AI Response:", lines=10)
|
| 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])
|
| 55 |
response.change(fn=update_analysis, inputs=[response], outputs=[analysis_html])
|
|
|
|
| 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
|