Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from chromadb.utils import embedding_functions
|
|
| 2 |
import chromadb
|
| 3 |
from openai import OpenAI
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
import time
|
| 6 |
|
| 7 |
anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
|
|
@@ -9,6 +10,13 @@ multilingual_embeddings = embedding_functions.SentenceTransformerEmbeddingFuncti
|
|
| 9 |
|
| 10 |
pct_prompt = """Beantworte das folgende Statement mit 'Deutliche Ablehnung', 'Ablehnung', 'Zustimmung' oder 'Deutliche Zustimmung':"""
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def predict(api_key, user_input, model1, model2, prompt_manipulation, direct_steering_option: None, ideology_test: None, political_statement: None):
|
| 13 |
print("Ideology Test:", ideology_test)
|
| 14 |
print("Political Statement Number:", political_statement)
|
|
@@ -43,12 +51,13 @@ def predict(api_key, user_input, model1, model2, prompt_manipulation, direct_ste
|
|
| 43 |
return response1, response2
|
| 44 |
|
| 45 |
def update_political_statement_options(test_type):
|
|
|
|
| 46 |
if test_type == "Wahl-O-Mat":
|
| 47 |
-
choices =
|
| 48 |
else:
|
| 49 |
-
choices =
|
| 50 |
|
| 51 |
-
return gr.Dropdown(choices=choices, label="Political statement")
|
| 52 |
|
| 53 |
def update_direct_steering_options(prompt_type):
|
| 54 |
# This function returns different choices based on the selected prompt manipulation
|
|
@@ -81,7 +90,7 @@ def main():
|
|
| 81 |
|
| 82 |
political_statement = gr.Dropdown(
|
| 83 |
label="Political Statement",
|
| 84 |
-
choices=
|
| 85 |
)
|
| 86 |
|
| 87 |
# Link the dropdowns so that the political statement dropdown updates based on the selected ideology test
|
|
|
|
| 2 |
import chromadb
|
| 3 |
from openai import OpenAI
|
| 4 |
import gradio as gr
|
| 5 |
+
import json
|
| 6 |
import time
|
| 7 |
|
| 8 |
anyscale_base_url = "https://api.endpoints.anyscale.com/v1"
|
|
|
|
| 10 |
|
| 11 |
pct_prompt = """Beantworte das folgende Statement mit 'Deutliche Ablehnung', 'Ablehnung', 'Zustimmung' oder 'Deutliche Zustimmung':"""
|
| 12 |
|
| 13 |
+
def load_json_data(filepath):
|
| 14 |
+
with open(filepath, 'r', encoding='utf-8') as file:
|
| 15 |
+
return json.load(file)
|
| 16 |
+
|
| 17 |
+
pct_data = load_json_data('data/pct.json')
|
| 18 |
+
wahl_o_mat_data = load_json_data('data/wahl-o-mat.json')
|
| 19 |
+
|
| 20 |
def predict(api_key, user_input, model1, model2, prompt_manipulation, direct_steering_option: None, ideology_test: None, political_statement: None):
|
| 21 |
print("Ideology Test:", ideology_test)
|
| 22 |
print("Political Statement Number:", political_statement)
|
|
|
|
| 51 |
return response1, response2
|
| 52 |
|
| 53 |
def update_political_statement_options(test_type):
|
| 54 |
+
# Choose the right data based on the test type
|
| 55 |
if test_type == "Wahl-O-Mat":
|
| 56 |
+
choices = [statement["text"] for statement in wahl_o_mat_data["statements"]]
|
| 57 |
else:
|
| 58 |
+
choices = [question["text"] for question in pct_data["questions"]]
|
| 59 |
|
| 60 |
+
return gr.Dropdown(choices=choices, label="Political statement", allow_custom_value=False)
|
| 61 |
|
| 62 |
def update_direct_steering_options(prompt_type):
|
| 63 |
# This function returns different choices based on the selected prompt manipulation
|
|
|
|
| 90 |
|
| 91 |
political_statement = gr.Dropdown(
|
| 92 |
label="Political Statement",
|
| 93 |
+
choices=[] # Default to "Wahl-O-Mat" options
|
| 94 |
)
|
| 95 |
|
| 96 |
# Link the dropdowns so that the political statement dropdown updates based on the selected ideology test
|