Spaces:
Sleeping
Sleeping
Commit ·
61bde96
1
Parent(s): e06afeb
Fix Together API import and usage
Browse files- app.py +9 -8
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -3,8 +3,7 @@ import numpy as np
|
|
| 3 |
import speech_recognition as sr
|
| 4 |
from sentence_transformers import SentenceTransformer
|
| 5 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
-
import
|
| 7 |
-
from together import Together
|
| 8 |
import json
|
| 9 |
import re
|
| 10 |
from dotenv import load_dotenv
|
|
@@ -16,15 +15,15 @@ from gtts import gTTS
|
|
| 16 |
import uuid
|
| 17 |
import base64
|
| 18 |
import io
|
|
|
|
| 19 |
|
| 20 |
load_dotenv()
|
| 21 |
|
| 22 |
app = Flask(__name__)
|
| 23 |
app.secret_key = os.urandom(24)
|
| 24 |
|
| 25 |
-
# Initialize Together
|
| 26 |
-
|
| 27 |
-
client = Together(api_key=your_api_key)
|
| 28 |
|
| 29 |
def prompt_llm(prompt, show_cost=False):
|
| 30 |
"""Function to send prompt to an LLM via the Together API."""
|
|
@@ -37,11 +36,13 @@ def prompt_llm(prompt, show_cost=False):
|
|
| 37 |
print(f"Estimated cost for {model}: ${cost:.10f}\n")
|
| 38 |
|
| 39 |
try:
|
| 40 |
-
response =
|
|
|
|
| 41 |
model=model,
|
| 42 |
-
|
|
|
|
| 43 |
)
|
| 44 |
-
content = response
|
| 45 |
|
| 46 |
# Safety check for empty responses
|
| 47 |
if not content or len(content.strip()) < 10:
|
|
|
|
| 3 |
import speech_recognition as sr
|
| 4 |
from sentence_transformers import SentenceTransformer
|
| 5 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
+
import together
|
|
|
|
| 7 |
import json
|
| 8 |
import re
|
| 9 |
from dotenv import load_dotenv
|
|
|
|
| 15 |
import uuid
|
| 16 |
import base64
|
| 17 |
import io
|
| 18 |
+
import requests
|
| 19 |
|
| 20 |
load_dotenv()
|
| 21 |
|
| 22 |
app = Flask(__name__)
|
| 23 |
app.secret_key = os.urandom(24)
|
| 24 |
|
| 25 |
+
# Initialize Together API
|
| 26 |
+
together.api_key = os.getenv("TOGETHER_API_KEY", "")
|
|
|
|
| 27 |
|
| 28 |
def prompt_llm(prompt, show_cost=False):
|
| 29 |
"""Function to send prompt to an LLM via the Together API."""
|
|
|
|
| 36 |
print(f"Estimated cost for {model}: ${cost:.10f}\n")
|
| 37 |
|
| 38 |
try:
|
| 39 |
+
response = together.Complete.create(
|
| 40 |
+
prompt=prompt,
|
| 41 |
model=model,
|
| 42 |
+
max_tokens=1024,
|
| 43 |
+
temperature=0.7,
|
| 44 |
)
|
| 45 |
+
content = response['output']['choices'][0]['text']
|
| 46 |
|
| 47 |
# Safety check for empty responses
|
| 48 |
if not content or len(content.strip()) < 10:
|
requirements.txt
CHANGED
|
@@ -6,6 +6,6 @@ huggingface_hub==0.12.1
|
|
| 6 |
sentence-transformers==2.2.2
|
| 7 |
scikit-learn==1.2.2
|
| 8 |
requests==2.31.0
|
| 9 |
-
together==0.1.5
|
| 10 |
python-dotenv==1.0.0
|
| 11 |
gtts==2.3.2
|
|
|
|
| 6 |
sentence-transformers==2.2.2
|
| 7 |
scikit-learn==1.2.2
|
| 8 |
requests==2.31.0
|
| 9 |
+
together-python==0.1.5
|
| 10 |
python-dotenv==1.0.0
|
| 11 |
gtts==2.3.2
|