Tech-Meld commited on
Commit
ad00e70
·
verified ·
1 Parent(s): 42bf6e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -45
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" # Change to your desired model
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
- iface = gr.Interface(
107
- fn=get_response,
108
- inputs=[
109
- gr.Textbox(label="Your message:", lines=5, placeholder="Ask me anything...", show_label=True),
110
- gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, value=0.7),
111
- gr.Slider(label="Top p", minimum=0.1, maximum=1.0, step=0.1, value=0.9),
112
- gr.Slider(label="Top k", minimum=1, maximum=100, step=1, value=50),
113
- gr.Slider(label="Max length", minimum=10, maximum=1000, step=10, value=250),
114
- ],
115
- outputs=[
116
- gr.TextArea(label="AI Response:", lines=10),
117
- gr.HTML(elem_id="analysis"),
118
- ],
119
- title="NVIDIA AI Chat",
120
- description="Engage in a conversation with our advanced AI model. Customize the response using various parameters.",
121
- theme="default",
122
- css=css,
123
- layout="vertical",
124
- allow_flagging="never",
125
- )
126
-
127
- # --- Dynamic Background ---
128
-
129
- def update_background():
130
- while True:
131
- r = random.randint(0, 255)
132
- g = 255 # Keep the green component constant
133
- b = random.randint(0, 255)
134
- iface.root.style.background_color = f"rgb({r}, {g}, {b})"
135
- time.sleep(1)
136
-
137
- # Start a separate thread to update the background color
138
- gr.Interface.update(update_background, inputs=[], outputs=[], live=True)
139
-
140
- # --- Analysis Logic ---
141
-
142
- def update_analysis(response):
143
- analysis = analyze_text(response)
144
- analysis_str = f"<div class='analysis-container'>Number of characters: {analysis['Number of characters']}<br>" \
145
- f"Number of words: {analysis['Number of words']}<br>" \
146
- f"Number of tokens: {analysis['Number of tokens']}</div>"
147
- iface.update(analysis=analysis_str, live=True)
148
-
149
- iface.outputs[0].postprocess = update_analysis
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)