Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,6 @@ from cerebras.cloud.sdk import Cerebras
|
|
| 6 |
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv()
|
| 9 |
-
|
| 10 |
client = Cerebras(
|
| 11 |
api_key=os.environ.get("CEREBRAS_API_KEY")
|
| 12 |
)
|
|
@@ -29,25 +28,21 @@ def chat(user_message, history):
|
|
| 29 |
{"role": "system", "content": "You are a helpful assistant."},
|
| 30 |
{"role": "user", "content": user_message}
|
| 31 |
],
|
| 32 |
-
model="
|
| 33 |
stream=True,
|
| 34 |
max_completion_tokens=65536,
|
| 35 |
temperature=1,
|
| 36 |
top_p=1
|
| 37 |
)
|
| 38 |
-
|
| 39 |
response_text = ""
|
| 40 |
for chunk in stream:
|
| 41 |
if chunk.choices[0].delta.content:
|
| 42 |
response_text += chunk.choices[0].delta.content
|
| 43 |
-
|
| 44 |
response_text = clean_response(response_text)
|
| 45 |
-
|
| 46 |
history = history or []
|
| 47 |
history.append({"role": "user", "content": user_message})
|
| 48 |
history.append({"role": "assistant", "content": response_text})
|
| 49 |
return history
|
| 50 |
-
|
| 51 |
except Exception as e:
|
| 52 |
history = history or []
|
| 53 |
history.append({"role": "user", "content": user_message})
|
|
@@ -56,12 +51,10 @@ def chat(user_message, history):
|
|
| 56 |
|
| 57 |
with gr.Blocks() as demo:
|
| 58 |
gr.Markdown("## Chat")
|
| 59 |
-
|
| 60 |
chatbot = gr.Chatbot(
|
| 61 |
label="Conversation",
|
| 62 |
height=600
|
| 63 |
)
|
| 64 |
-
|
| 65 |
with gr.Row():
|
| 66 |
msg = gr.Textbox(
|
| 67 |
label="Ask something",
|
|
@@ -69,7 +62,6 @@ with gr.Blocks() as demo:
|
|
| 69 |
scale=4
|
| 70 |
)
|
| 71 |
clear = gr.Button("Clear")
|
| 72 |
-
|
| 73 |
msg.submit(chat, [msg, chatbot], chatbot)
|
| 74 |
clear.click(lambda: [], None, chatbot)
|
| 75 |
|
|
|
|
| 6 |
|
| 7 |
# Load environment variables
|
| 8 |
load_dotenv()
|
|
|
|
| 9 |
client = Cerebras(
|
| 10 |
api_key=os.environ.get("CEREBRAS_API_KEY")
|
| 11 |
)
|
|
|
|
| 28 |
{"role": "system", "content": "You are a helpful assistant."},
|
| 29 |
{"role": "user", "content": user_message}
|
| 30 |
],
|
| 31 |
+
model="gpt-oss-120b", # ← Updated to free-tier model
|
| 32 |
stream=True,
|
| 33 |
max_completion_tokens=65536,
|
| 34 |
temperature=1,
|
| 35 |
top_p=1
|
| 36 |
)
|
|
|
|
| 37 |
response_text = ""
|
| 38 |
for chunk in stream:
|
| 39 |
if chunk.choices[0].delta.content:
|
| 40 |
response_text += chunk.choices[0].delta.content
|
|
|
|
| 41 |
response_text = clean_response(response_text)
|
|
|
|
| 42 |
history = history or []
|
| 43 |
history.append({"role": "user", "content": user_message})
|
| 44 |
history.append({"role": "assistant", "content": response_text})
|
| 45 |
return history
|
|
|
|
| 46 |
except Exception as e:
|
| 47 |
history = history or []
|
| 48 |
history.append({"role": "user", "content": user_message})
|
|
|
|
| 51 |
|
| 52 |
with gr.Blocks() as demo:
|
| 53 |
gr.Markdown("## Chat")
|
|
|
|
| 54 |
chatbot = gr.Chatbot(
|
| 55 |
label="Conversation",
|
| 56 |
height=600
|
| 57 |
)
|
|
|
|
| 58 |
with gr.Row():
|
| 59 |
msg = gr.Textbox(
|
| 60 |
label="Ask something",
|
|
|
|
| 62 |
scale=4
|
| 63 |
)
|
| 64 |
clear = gr.Button("Clear")
|
|
|
|
| 65 |
msg.submit(chat, [msg, chatbot], chatbot)
|
| 66 |
clear.click(lambda: [], None, chatbot)
|
| 67 |
|