Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,16 +26,23 @@ def load_pipeline(task, model):
|
|
| 26 |
|
| 27 |
# Function to predict using Hugging Face models and OpenAI models
|
| 28 |
def predict(task, model, text):
|
| 29 |
-
|
| 30 |
-
response = openai.ChatCompletion.create(
|
| 31 |
-
model="gpt-4" if model == "GPT-4" else "gpt-3.5-turbo",
|
| 32 |
-
messages=[{"role": "user", "content": text}]
|
| 33 |
-
)
|
| 34 |
-
results = [{"label": response.choices[0].message['content'].strip()}]
|
| 35 |
-
else:
|
| 36 |
selected_pipeline = load_pipeline(task, model)
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Function to benchmark Hugging Face models and OpenAI models
|
| 41 |
def benchmark(task, model, file):
|
|
|
|
| 26 |
|
| 27 |
# Function to predict using Hugging Face models and OpenAI models
|
| 28 |
def predict(task, model, text):
|
| 29 |
+
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
selected_pipeline = load_pipeline(task, model)
|
| 31 |
+
if model in ["ChatGPT", "GPT4"]:
|
| 32 |
+
# OpenAI API request
|
| 33 |
+
response = openai.ChatCompletion.create(
|
| 34 |
+
model=MODELS[model],
|
| 35 |
+
messages=[{"role": "user", "content": text}]
|
| 36 |
+
)
|
| 37 |
+
return response['choices'][0]['message']['content']
|
| 38 |
+
else:
|
| 39 |
+
# Hugging Face pipeline
|
| 40 |
+
results = selected_pipeline(text)
|
| 41 |
+
return results
|
| 42 |
+
except Exception as e:
|
| 43 |
+
print(f"Error in prediction: {e}")
|
| 44 |
+
return {"error": str(e)}
|
| 45 |
+
|
| 46 |
|
| 47 |
# Function to benchmark Hugging Face models and OpenAI models
|
| 48 |
def benchmark(task, model, file):
|