Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,13 @@
|
|
| 1 |
-
import os
|
| 2 |
-
from groq import Groq
|
| 3 |
import gradio as gr
|
| 4 |
-
from
|
| 5 |
|
| 6 |
class ConversationalAI:
|
| 7 |
def __init__(self):
|
| 8 |
-
os.environ["GROQ_API_KEY"] = GROQ_API_KEY
|
| 9 |
self.client = Groq()
|
| 10 |
self.system_prompt = {
|
| 11 |
"role": "system",
|
| 12 |
"content": "You are a useful assistant. You reply with efficient answers."
|
| 13 |
}
|
| 14 |
-
self.logged_in = False # Track login status
|
| 15 |
|
| 16 |
async def chat_groq(self, message, history):
|
| 17 |
messages = [self.system_prompt]
|
|
@@ -38,29 +34,9 @@ class ConversationalAI:
|
|
| 38 |
response_content += chunk.choices[0].delta.content
|
| 39 |
yield response_content
|
| 40 |
|
| 41 |
-
def login(self, username, password):
|
| 42 |
-
# Simple authentication logic
|
| 43 |
-
if username == "admin" and password == "password": # Replace with real authentication
|
| 44 |
-
self.logged_in = True
|
| 45 |
-
return "Login successful! You can now access the chat interface."
|
| 46 |
-
else:
|
| 47 |
-
return "Invalid username or password. Please try again."
|
| 48 |
-
|
| 49 |
-
def create_chat_interface(self):
|
| 50 |
-
def on_login_click(username, password, login_output):
|
| 51 |
-
result_msg = self.login(username, password)
|
| 52 |
-
login_output.value = result_msg
|
| 53 |
-
if self.logged_in:
|
| 54 |
-
demo.replace(gr.ChatInterface(self.chat_groq, clear_btn=None, undo_btn=None, retry_btn=None))
|
| 55 |
-
|
| 56 |
-
demo = gr.ChatInterface(self.chat_groq, placeholder="Type your message here...",
|
| 57 |
-
submit_btn_label="Send",
|
| 58 |
-
layout="vertical")
|
| 59 |
-
|
| 60 |
-
return demo
|
| 61 |
-
|
| 62 |
if __name__ == "__main__":
|
| 63 |
ai = ConversationalAI()
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from groq import Groq
|
| 3 |
|
| 4 |
class ConversationalAI:
|
| 5 |
def __init__(self):
|
|
|
|
| 6 |
self.client = Groq()
|
| 7 |
self.system_prompt = {
|
| 8 |
"role": "system",
|
| 9 |
"content": "You are a useful assistant. You reply with efficient answers."
|
| 10 |
}
|
|
|
|
| 11 |
|
| 12 |
async def chat_groq(self, message, history):
|
| 13 |
messages = [self.system_prompt]
|
|
|
|
| 34 |
response_content += chunk.choices[0].delta.content
|
| 35 |
yield response_content
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if __name__ == "__main__":
|
| 38 |
ai = ConversationalAI()
|
| 39 |
+
interface = gr.Interface(ai.chat_groq, inputs=gr.Textbox(label="Message", placeholder="Type your message here..."),
|
| 40 |
+
outputs=gr.Textbox(label="Response", placeholder="Response will appear here..."),
|
| 41 |
+
theme="compact")
|
| 42 |
+
interface.launch()
|