Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ from openai import OpenAI
|
|
| 3 |
from pypdf import PdfReader
|
| 4 |
import gradio as gr
|
| 5 |
import json
|
|
|
|
| 6 |
import datetime
|
| 7 |
from pathlib import Path
|
| 8 |
|
|
@@ -22,7 +23,12 @@ def save_usage(total_cost):
|
|
| 22 |
}, f)
|
| 23 |
|
| 24 |
load_dotenv(override=True)
|
| 25 |
-
client = OpenAI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# === CONFIGURABLE BUDGET LIMIT (USD) ===
|
| 27 |
USAGE_LIMIT_PER_DAY = 0.1 # USD
|
| 28 |
USAGE_FILE = Path("daily_usage.json")
|
|
@@ -61,7 +67,7 @@ def chat(message, history):
|
|
| 61 |
return "Daily usage limit reached. Please try again tomorrow."
|
| 62 |
|
| 63 |
messages = [{"role": "system", "content": system_prompt}] + history + [{"role": "user", "content": message}]
|
| 64 |
-
response = client.chat.completions.create(model="
|
| 65 |
usage = response.usage
|
| 66 |
input_tokens = usage.prompt_tokens
|
| 67 |
output_tokens = usage.completion_tokens
|
|
|
|
| 3 |
from pypdf import PdfReader
|
| 4 |
import gradio as gr
|
| 5 |
import json
|
| 6 |
+
import os
|
| 7 |
import datetime
|
| 8 |
from pathlib import Path
|
| 9 |
|
|
|
|
| 23 |
}, f)
|
| 24 |
|
| 25 |
load_dotenv(override=True)
|
| 26 |
+
# client = OpenAI()
|
| 27 |
+
|
| 28 |
+
client = OpenAI(
|
| 29 |
+
api_key=os.getenv('DEEPSEEK_API_KEY'),
|
| 30 |
+
base_url="https://api.deepseek.com/v1" # Example endpoint; replace with the actual DeepSeek endpoint
|
| 31 |
+
)
|
| 32 |
# === CONFIGURABLE BUDGET LIMIT (USD) ===
|
| 33 |
USAGE_LIMIT_PER_DAY = 0.1 # USD
|
| 34 |
USAGE_FILE = Path("daily_usage.json")
|
|
|
|
| 67 |
return "Daily usage limit reached. Please try again tomorrow."
|
| 68 |
|
| 69 |
messages = [{"role": "system", "content": system_prompt}] + history + [{"role": "user", "content": message}]
|
| 70 |
+
response = client.chat.completions.create(model="deepseek-chat", messages=messages)
|
| 71 |
usage = response.usage
|
| 72 |
input_tokens = usage.prompt_tokens
|
| 73 |
output_tokens = usage.completion_tokens
|