Tech-Meld commited on
Commit
c11acf6
·
verified ·
1 Parent(s): 9636c68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -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"
8
  tokenizer = AutoTokenizer.from_pretrained(model_id)
9
  model = AutoModelForCausalLM.from_pretrained(model_id)
10
 
@@ -33,61 +33,50 @@ def analyze_text(text):
33
 
34
  # --- Interface ---
35
 
36
- def custom_textbox(label, lines, placeholder, show_label=True):
37
- textbox = gr.Textbox(label=label, lines=lines, placeholder=placeholder, show_label=show_label)
38
- html = gr.HTML(f"""
39
- <style>
40
- .gradio-textbox {
41
- background-color: #111111;
42
- color: #00FF00;
43
- border: 1px solid #00FF00;
44
- }
45
- </style>
46
- """)
47
- return textbox, html
48
-
49
  css = """
50
  .gradio-container {
51
- background-color: #000000; /* Black background for the container */
52
- font-family: 'Roboto', sans-serif; /* Use a font similar to Nvidia's style */
53
  }
54
 
55
  .gradio-interface {
56
- background-color: rgba(0, 0, 0, 0.8); /* Translucent black background */
57
  border: 3px solid #00FF00; /* Green border */
58
- border-radius: 15px; /* Rounded corners */
59
  padding: 20px;
60
  box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); /* Green shadow */
61
  }
62
 
63
  .gradio-button {
64
- background-color: #00FF00; /* Green button color */
65
  color: white;
66
  border: none;
67
  padding: 10px 20px;
68
- text-align: center;
69
- text-decoration: none;
70
- display: inline-block;
71
  font-size: 16px;
72
- margin: 4px 2px;
73
  cursor: pointer;
74
- border-radius: 5px; /* Rounded corners */
75
  }
76
 
77
  .gradio-button:hover {
78
  background-color: #00CC00; /* Darker green on hover */
79
  }
80
 
 
 
 
 
 
 
 
 
81
  .gradio-text-area {
82
- resize: vertical; /* Allow vertical resizing for text areas */
83
- background-color: #111111; /* Dark gray background for text areas */
84
- color: #00FF00; /* Green text color for text areas */
85
- border: 1px solid #00FF00; /* Green border for text areas */
86
  }
87
 
88
  .gradio-slider {
89
- background-color: #111111; /* Dark gray background for sliders */
90
- color: #00FF00; /* Green text color for sliders */
91
  }
92
 
93
  .gradio-slider .slider-bar {
@@ -98,20 +87,27 @@ css = """
98
  background-color: #00FF00; /* Green slider thumb */
99
  }
100
 
101
- h1 {
102
- color: #00FF00; /* Green heading color */
 
 
 
 
103
  text-align: center;
104
  }
105
 
106
- h2 {
107
- color: #00FF00; /* Green subheading color */
 
 
108
  }
109
  """
110
 
111
  iface = gr.Interface(
112
  fn=get_response,
113
  inputs=[
114
- *custom_textbox(label="Your message:", lines=5, placeholder="Ask me anything...", show_label=True),
 
115
  gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, value=0.7),
116
  gr.Slider(label="Top p", minimum=0.1, maximum=1.0, step=0.1, value=0.9),
117
  gr.Slider(label="Top k", minimum=1, maximum=100, step=1, value=50),
@@ -120,12 +116,12 @@ iface = gr.Interface(
120
  outputs=[
121
  gr.TextArea(label="AI Response:", lines=10,
122
  style={'background-color': '#111111', 'color': '#00FF00', 'border': '1px solid #00FF00'}),
123
- gr.Label(label="Text Analysis", elem_id="analysis", style={'color': '#00FF00'}),
124
  ],
125
  title="NVIDIA AI Chat",
126
  description="Engage in a conversation with our advanced AI model. Customize the response using various parameters.",
127
- theme="default", # Use a custom theme to override the default Gradio styling
128
- css=css, # Apply the CSS styles defined earlier
129
  layout="vertical",
130
  allow_flagging="never",
131
  )
@@ -137,8 +133,8 @@ def update_background():
137
  r = random.randint(0, 255)
138
  g = 255 # Keep the green component constant
139
  b = random.randint(0, 255)
140
- iface.root.style.background_color = f"rgb({r}, {g}, {b})" # Set dynamic background color
141
- time.sleep(1) # Update every second
142
 
143
  # Start a separate thread to update the background color
144
  gr.Interface.update(update_background, inputs=[], outputs=[], live=True)
@@ -147,11 +143,11 @@ gr.Interface.update(update_background, inputs=[], outputs=[], live=True)
147
 
148
  def update_analysis(response):
149
  analysis = analyze_text(response)
150
- analysis_str = f"Number of characters: {analysis['Number of characters']}\n" \
151
- f"Number of words: {analysis['Number of words']}\n" \
152
- f"Number of tokens: {analysis['Number of tokens']}"
153
- iface.update(analysis=analysis_str, live=True) # Update analysis section with the generated data
154
 
155
- iface.outputs[0].postprocess = update_analysis # Update analysis after every response
156
 
157
  iface.launch(debug=True)
 
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
  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 {
 
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
  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
+ style={'background-color': '#111111', 'color': '#00FF00', 'border': '1px solid #00FF00'}),
111
  gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, step=0.1, value=0.7),
112
  gr.Slider(label="Top p", minimum=0.1, maximum=1.0, step=0.1, value=0.9),
113
  gr.Slider(label="Top k", minimum=1, maximum=100, step=1, value=50),
 
116
  outputs=[
117
  gr.TextArea(label="AI Response:", lines=10,
118
  style={'background-color': '#111111', 'color': '#00FF00', 'border': '1px solid #00FF00'}),
119
+ gr.HTML(elem_id="analysis", style={'color': '#00FF00'}),
120
  ],
121
  title="NVIDIA AI Chat",
122
  description="Engage in a conversation with our advanced AI model. Customize the response using various parameters.",
123
+ theme="default",
124
+ css=css,
125
  layout="vertical",
126
  allow_flagging="never",
127
  )
 
133
  r = random.randint(0, 255)
134
  g = 255 # Keep the green component constant
135
  b = random.randint(0, 255)
136
+ iface.root.style.background_color = f"rgb({r}, {g}, {b})"
137
+ time.sleep(1)
138
 
139
  # Start a separate thread to update the background color
140
  gr.Interface.update(update_background, inputs=[], outputs=[], live=True)
 
143
 
144
  def update_analysis(response):
145
  analysis = analyze_text(response)
146
+ analysis_str = f"<div class='analysis-container'>Number of characters: {analysis['Number of characters']}<br>" \
147
+ f"Number of words: {analysis['Number of words']}<br>" \
148
+ f"Number of tokens: {analysis['Number of tokens']}</div>"
149
+ iface.update(analysis=analysis_str, live=True)
150
 
151
+ iface.outputs[0].postprocess = update_analysis
152
 
153
  iface.launch(debug=True)