Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
-
import pollinations
|
3 |
import pandas as pd
|
4 |
import os
|
5 |
from datetime import datetime
|
@@ -7,11 +7,16 @@ from huggingface_hub import HfApi
|
|
7 |
import pyarrow.parquet as pq
|
8 |
import pyarrow as pa
|
9 |
import requests
|
10 |
-
import json
|
11 |
|
12 |
-
# Initialize Pollinations text model
|
13 |
default_model = "openai"
|
14 |
-
model =
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
# Hugging Face setup
|
17 |
HF_TOKEN = os.getenv("HF_TOKEN") # Set in HF Space secrets
|
@@ -33,18 +38,32 @@ def fetch_models():
|
|
33 |
|
34 |
def change_model(selected_model):
|
35 |
global model
|
36 |
-
model =
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
return f"Switched to model: {selected_model}"
|
38 |
|
39 |
def chatbot_response(user_message, history, selected_model):
|
40 |
global conversation_history, model
|
41 |
# Ensure model is up-to-date
|
42 |
if model.model != selected_model:
|
43 |
-
model =
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
# Generate response
|
46 |
-
seed = int(datetime.now().timestamp())
|
47 |
-
response =
|
|
|
|
|
48 |
|
49 |
# Append to history with timestamp and model info
|
50 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
@@ -121,4 +140,4 @@ with gr.Blocks() as demo:
|
|
121 |
clear.click(lambda: ([], []), None, [chatbot, msg], queue=False)
|
122 |
|
123 |
# Launch the demo
|
124 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import pollinations as pl
|
3 |
import pandas as pd
|
4 |
import os
|
5 |
from datetime import datetime
|
|
|
7 |
import pyarrow.parquet as pq
|
8 |
import pyarrow as pa
|
9 |
import requests
|
|
|
10 |
|
11 |
+
# Initialize Pollinations text model
|
12 |
default_model = "openai"
|
13 |
+
model = pl.Text(
|
14 |
+
model=default_model,
|
15 |
+
system="You are a helpful AI assistant.",
|
16 |
+
contextual=True,
|
17 |
+
seed="random",
|
18 |
+
reasoning_effort="medium"
|
19 |
+
)
|
20 |
|
21 |
# Hugging Face setup
|
22 |
HF_TOKEN = os.getenv("HF_TOKEN") # Set in HF Space secrets
|
|
|
38 |
|
39 |
def change_model(selected_model):
|
40 |
global model
|
41 |
+
model = pl.Text(
|
42 |
+
model=selected_model,
|
43 |
+
system="You are a helpful AI assistant.",
|
44 |
+
contextual=True,
|
45 |
+
seed="random",
|
46 |
+
reasoning_effort="medium"
|
47 |
+
)
|
48 |
return f"Switched to model: {selected_model}"
|
49 |
|
50 |
def chatbot_response(user_message, history, selected_model):
|
51 |
global conversation_history, model
|
52 |
# Ensure model is up-to-date
|
53 |
if model.model != selected_model:
|
54 |
+
model = pl.Text(
|
55 |
+
model=selected_model,
|
56 |
+
system="You are a helpful AI assistant.",
|
57 |
+
contextual=True,
|
58 |
+
seed="random",
|
59 |
+
reasoning_effort="medium"
|
60 |
+
)
|
61 |
|
62 |
+
# Generate response with streaming
|
63 |
+
seed = int(datetime.now().timestamp())
|
64 |
+
response = ""
|
65 |
+
for token in model(user_message, stream=True, seed=seed):
|
66 |
+
response += token
|
67 |
|
68 |
# Append to history with timestamp and model info
|
69 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
140 |
clear.click(lambda: ([], []), None, [chatbot, msg], queue=False)
|
141 |
|
142 |
# Launch the demo
|
143 |
+
demo.queue().launch()
|