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 |
|
|
@@ -103,49 +103,70 @@ h1, h2 {
|
|
| 103 |
}
|
| 104 |
"""
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
gr.
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
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 |
|
|
|
|
| 103 |
}
|
| 104 |
"""
|
| 105 |
|
| 106 |
+
with gr.Blocks() as iface:
|
| 107 |
+
gr.Markdown(
|
| 108 |
+
"""
|
| 109 |
+
# NVIDIA AI Chat
|
| 110 |
+
Engage in a conversation with our advanced AI model. Customize the response using various parameters.
|
| 111 |
+
"""
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
with gr.Row():
|
| 115 |
+
input_text = gr.Textbox(
|
| 116 |
+
label="Your message:", lines=5, placeholder="Ask me anything...", show_label=True
|
| 117 |
+
)
|
| 118 |
+
gr.HTML(
|
| 119 |
+
f"""
|
| 120 |
+
<style>
|
| 121 |
+
.gradio-textbox {
|
| 122 |
+
background-color: #111111;
|
| 123 |
+
color: #00FF00;
|
| 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])
|
| 147 |
+
|
| 148 |
+
# --- Dynamic Background ---
|
| 149 |
+
|
| 150 |
+
def update_background():
|
| 151 |
+
while True:
|
| 152 |
+
r = random.randint(0, 255)
|
| 153 |
+
g = 255 # Keep the green component constant
|
| 154 |
+
b = random.randint(0, 255)
|
| 155 |
+
iface.root.style.background_color = f"rgb({r}, {g}, {b})"
|
| 156 |
+
time.sleep(1)
|
| 157 |
+
|
| 158 |
+
# Start a separate thread to update the background color
|
| 159 |
+
gr.Interface.update(update_background, inputs=[], outputs=[], live=True)
|
| 160 |
+
|
| 161 |
+
# --- Analysis Logic ---
|
| 162 |
+
|
| 163 |
+
def update_analysis(response):
|
| 164 |
+
analysis = analyze_text(response)
|
| 165 |
+
analysis_str = f"<div class='analysis-container'>Number of characters: {analysis['Number of characters']}<br>" \
|
| 166 |
+
f"Number of words: {analysis['Number of words']}<br>" \
|
| 167 |
+
f"Number of tokens: {analysis['Number of tokens']}</div>"
|
| 168 |
+
iface.update(analysis=analysis_str, live=True)
|
| 169 |
+
|
| 170 |
+
iface.outputs[0].postprocess = update_analysis
|
| 171 |
|
| 172 |
iface.launch(debug=True)
|