Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -34,14 +34,14 @@ custom_css = """
|
|
34 |
}
|
35 |
"""
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
def switch_model(model_choice):
|
41 |
-
"""Function to switch between models"""
|
42 |
-
return gr.update(visible=False), gr.update(visible=True), model_choice
|
43 |
|
44 |
with gr.Blocks(fill_height=True, theme="soft", css=custom_css) as demo:
|
|
|
|
|
|
|
45 |
with gr.Row():
|
46 |
# Sidebar
|
47 |
with gr.Column(scale=1):
|
@@ -66,9 +66,6 @@ with gr.Blocks(fill_height=True, theme="soft", css=custom_css) as demo:
|
|
66 |
# Login button
|
67 |
login_button = gr.LoginButton("Sign in with Hugging Face", size="lg")
|
68 |
|
69 |
-
# Reload button to apply model change
|
70 |
-
reload_btn = gr.Button("🔄 Apply Model Change", variant="primary", size="lg")
|
71 |
-
|
72 |
# Additional options
|
73 |
with gr.Accordion("⚙️ Advanced Options", open=False):
|
74 |
gr.Markdown("*These options will be available after model implementation*")
|
@@ -92,37 +89,77 @@ with gr.Blocks(fill_height=True, theme="soft", css=custom_css) as demo:
|
|
92 |
with gr.Group(elem_classes="main-container"):
|
93 |
gr.Markdown("## 💬 Chat Interface")
|
94 |
|
95 |
-
#
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
-
|
101 |
-
gr.Markdown("### Model: openai/gpt-oss-20b")
|
102 |
-
gr.load("models/openai/gpt-oss-20b", accept_token=login_button, provider="fireworks-ai")
|
103 |
|
104 |
-
#
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
107 |
inputs=[model_dropdown],
|
108 |
-
outputs=[
|
109 |
-
)
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
)
|
114 |
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
return gr.update(visible=False), gr.update(visible=True)
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
)
|
127 |
|
128 |
demo.launch()
|
|
|
34 |
}
|
35 |
"""
|
36 |
|
37 |
+
def chat_fn(message, history, model_choice):
|
38 |
+
"""Placeholder chat function"""
|
39 |
+
return f"Response from {model_choice}: {message}"
|
|
|
|
|
|
|
40 |
|
41 |
with gr.Blocks(fill_height=True, theme="soft", css=custom_css) as demo:
|
42 |
+
# State variable to track current model
|
43 |
+
current_model = gr.State("openai/gpt-oss-120b")
|
44 |
+
|
45 |
with gr.Row():
|
46 |
# Sidebar
|
47 |
with gr.Column(scale=1):
|
|
|
66 |
# Login button
|
67 |
login_button = gr.LoginButton("Sign in with Hugging Face", size="lg")
|
68 |
|
|
|
|
|
|
|
69 |
# Additional options
|
70 |
with gr.Accordion("⚙️ Advanced Options", open=False):
|
71 |
gr.Markdown("*These options will be available after model implementation*")
|
|
|
89 |
with gr.Group(elem_classes="main-container"):
|
90 |
gr.Markdown("## 💬 Chat Interface")
|
91 |
|
92 |
+
# Display current model
|
93 |
+
model_display = gr.Markdown(f"### Model: openai/gpt-oss-120b")
|
94 |
+
|
95 |
+
# Single chat interface that works with both models
|
96 |
+
chatbot = gr.Chatbot(
|
97 |
+
height=400,
|
98 |
+
show_label=False,
|
99 |
+
elem_classes="main-container"
|
100 |
+
)
|
101 |
+
|
102 |
+
with gr.Row():
|
103 |
+
msg = gr.Textbox(
|
104 |
+
placeholder="Type your message here...",
|
105 |
+
show_label=False,
|
106 |
+
scale=9
|
107 |
+
)
|
108 |
+
submit_btn = gr.Button("Send", variant="primary", scale=1)
|
109 |
|
110 |
+
clear_btn = gr.Button("🗑️ Clear Chat", variant="secondary")
|
|
|
|
|
111 |
|
112 |
+
# Update model display when dropdown changes
|
113 |
+
def update_model_display(model_choice):
|
114 |
+
return f"### Model: {model_choice}", model_choice
|
115 |
+
|
116 |
+
model_dropdown.change(
|
117 |
+
fn=update_model_display,
|
118 |
inputs=[model_dropdown],
|
119 |
+
outputs=[model_display, current_model]
|
120 |
+
)
|
121 |
+
|
122 |
+
# Chat functionality
|
123 |
+
def respond(message, chat_history, model):
|
124 |
+
if not message:
|
125 |
+
return "", chat_history
|
126 |
+
|
127 |
+
# Add user message to history
|
128 |
+
chat_history = chat_history + [[message, None]]
|
129 |
+
|
130 |
+
# Generate bot response (placeholder - replace with actual model call)
|
131 |
+
bot_response = f"[{model.split('/')[-1]}]: This is a placeholder response. In production, this would connect to the {model} via Fireworks AI API."
|
132 |
+
|
133 |
+
# Update the last message with bot response
|
134 |
+
chat_history[-1][1] = bot_response
|
135 |
+
|
136 |
+
return "", chat_history
|
137 |
+
|
138 |
+
# Submit message on button click or enter
|
139 |
+
submit_btn.click(
|
140 |
+
fn=respond,
|
141 |
+
inputs=[msg, chatbot, current_model],
|
142 |
+
outputs=[msg, chatbot]
|
143 |
)
|
144 |
|
145 |
+
msg.submit(
|
146 |
+
fn=respond,
|
147 |
+
inputs=[msg, chatbot, current_model],
|
148 |
+
outputs=[msg, chatbot]
|
149 |
+
)
|
|
|
150 |
|
151 |
+
# Clear chat
|
152 |
+
clear_btn.click(
|
153 |
+
fn=lambda: (None, ""),
|
154 |
+
inputs=[],
|
155 |
+
outputs=[chatbot, msg]
|
156 |
+
)
|
157 |
+
|
158 |
+
# Show info message on login
|
159 |
+
login_button.click(
|
160 |
+
fn=lambda: gr.Info("Please authenticate with Hugging Face to access the models"),
|
161 |
+
inputs=[],
|
162 |
+
outputs=[]
|
163 |
)
|
164 |
|
165 |
demo.launch()
|