fabianzarncke commited on
Commit
97a0335
·
verified ·
1 Parent(s): 1b46271

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -6
app.py CHANGED
@@ -7,19 +7,81 @@ For more information on `huggingface_hub` Inference API support, please check th
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
  def preprocess_user_input(input_text):
10
- # Example: Add a prefix to the user input
11
- processed_text = f"Explain to me what a {input_text} is!"
12
 
13
- # system_message = "Ersetze im folgenden Prompt alle wertenden adjektive mit neutraleren synonymen. Hier ist ein Beispiel: Inwiefern ist Gold kaufen geizig? wird zu: Inwiefern ist Gold kaufen ökonomisch?"
 
 
 
 
14
  system_message = "In the following prompt replace all biased adjectives with neutral synonyms. And only return me the modified prompt. Here is an example: Inhowfar is buying gold stingy? becomes: Inhowfar is buying gold economical?"
 
 
 
 
 
 
 
15
 
16
- finalPrompt = insideRespond(input_text, system_message)
17
- print(finalPrompt)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- return finalPrompt
20
 
 
 
 
21
 
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  def insideRespond(
25
  message,
 
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
  def preprocess_user_input(input_text):
 
 
10
 
11
+ #do something
12
+
13
+
14
+ def full_auto_adjective_replacement(input_text)
15
+
16
  system_message = "In the following prompt replace all biased adjectives with neutral synonyms. And only return me the modified prompt. Here is an example: Inhowfar is buying gold stingy? becomes: Inhowfar is buying gold economical?"
17
+
18
+ processed_promt = insideRespond(input_text, system_message)
19
+ print processed_promt
20
+
21
+ print get_adjectives(input_text)
22
+
23
+ return processed_promt
24
 
25
+
26
+ def full_adjective_replacement(input_text)
27
+
28
+
29
+ adjectives = get_adjectives(input_text)
30
+
31
+ text = input_text
32
+ print(text)
33
+
34
+ for adjective in adjectives
35
+ adjective_biased = determine_biased_adjective(input_text, adjective)
36
+ if adjective_biased
37
+ new_adjective = replace_biased_adjective(adjective)
38
+ text = replace_adjective_in_text(text, adjective, new_adjective)
39
+ print(text)
40
+
41
+
42
+
43
+ def get_adjectives(input_text):
44
+
45
+ system_message = "Return all adjectives from the following text in a comma seperated bracket. Example: [stingy, smart, clean]"
46
+
47
+ adjectives = insideRepsond(input_text, system_message)
48
+ print(adjectives)
49
+
50
+ return adjectives
51
 
 
52
 
53
+ def determine_biased_adjective(input_text, adjective)
54
+
55
+ system_message = "Determine wether the following adjective is biased in the following Text. Return only yes or no as a single word."
56
 
57
+ processed_text = f"Text: {input_text} /n Adjective: {adjective}"
58
 
59
+ answer = insideRespond(processed_text, system_message)
60
+
61
+ if answer == "yes"
62
+ return true
63
+ if answer == "no"
64
+ return false
65
+
66
+
67
+ def replace_biased_adjective(adjective)
68
+
69
+ system_message = "Replace the following adjective with a more neutral one. Return only the new adjective as a single word."
70
+
71
+ new_adjective insideRespond(adjective, system_message)
72
+
73
+ return new_adjective
74
+
75
+
76
+ def replace_adjective_in_text(input_text, old_adjective, new_adjective)
77
+
78
+ processed_text = input_text.replace(old_adjective, new_adjective)
79
+
80
+ return processed_text
81
+
82
+
83
+
84
+
85
 
86
  def insideRespond(
87
  message,