Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,34 @@ def check_hallucination(assertion,citation):
|
|
| 28 |
|
| 29 |
return f"**hullicination score:** {output}"
|
| 30 |
|
|
|
|
|
|
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
def process_speech(input_language, audio_input):
|
| 34 |
"""
|
|
@@ -280,11 +307,13 @@ def process_and_query(input_language=None,audio_input=None,image_input=None,text
|
|
| 280 |
# Process the summary with OpenAI
|
| 281 |
final_response = process_summary_with_openai(markdown_output)
|
| 282 |
|
| 283 |
-
#
|
| 284 |
-
|
| 285 |
|
| 286 |
-
# Return the processed summary along with the
|
| 287 |
-
return
|
|
|
|
|
|
|
| 288 |
except Exception as e:
|
| 289 |
return str(e)
|
| 290 |
|
|
@@ -424,7 +453,7 @@ with gr.Blocks(theme='ParityError/Anime') as iface :
|
|
| 424 |
text_input = gr.Textbox(label="input text",lines=5)
|
| 425 |
text_output = gr.Markdown(label="output text")
|
| 426 |
text_button = gr.Button("process text")
|
| 427 |
-
text_button.click(process_and_query, inputs=[input_language,audio_input,image_input,text_input], outputs=
|
| 428 |
gr.Examples([
|
| 429 |
["What is the proper treatment for buccal herpes?"],
|
| 430 |
["Male, 40 presenting with swollen glands and a rash"],
|
|
|
|
| 28 |
|
| 29 |
return f"**hullicination score:** {output}"
|
| 30 |
|
| 31 |
+
# Define the API parameters
|
| 32 |
+
VAPI_URL = "https://api-inference.huggingface.co/models/vectara/hallucination_evaluation_model"
|
| 33 |
|
| 34 |
+
headers = {"Authorization": f"Bearer {HuggingFace_Token}"}
|
| 35 |
+
|
| 36 |
+
# Function to query the API
|
| 37 |
+
def query(payload):
|
| 38 |
+
response = requests.post(VAPI_URL, headers=headers, json=payload)
|
| 39 |
+
return response.json()
|
| 40 |
+
|
| 41 |
+
# Function to evaluate hallucination
|
| 42 |
+
def evaluate_hallucination(input1, input2):
|
| 43 |
+
# Combine the inputs
|
| 44 |
+
combined_input = f"{input1}. {input2}"
|
| 45 |
+
|
| 46 |
+
# Make the API call
|
| 47 |
+
output = query({"inputs": combined_input})
|
| 48 |
+
|
| 49 |
+
# Extract the score from the output
|
| 50 |
+
score = output[0][0]['score']
|
| 51 |
+
|
| 52 |
+
# Generate a label based on the score
|
| 53 |
+
if score < 0.5:
|
| 54 |
+
label = "🔴", f"The score is less than 0.5, indicating low risk. Score: {score:.2f}"
|
| 55 |
+
else:
|
| 56 |
+
label = "🟢", f"The score is 0.5 or higher, indicating higher risk. Score: {score:.2f}"
|
| 57 |
+
|
| 58 |
+
return label
|
| 59 |
|
| 60 |
def process_speech(input_language, audio_input):
|
| 61 |
"""
|
|
|
|
| 307 |
# Process the summary with OpenAI
|
| 308 |
final_response = process_summary_with_openai(markdown_output)
|
| 309 |
|
| 310 |
+
# Evaluate hallucination
|
| 311 |
+
hallucination_label = evaluate_hallucination(final_response, markdown_output)
|
| 312 |
|
| 313 |
+
# Return the processed summary along with the hallucination label
|
| 314 |
+
return final_response, hallucination_label
|
| 315 |
+
|
| 316 |
+
return f"**Summary**: {final_response}\n\n**Full output**:\n{markdown_output}\n\n**Hallucination Evaluation**: {hallucination_message} {hallucination_result}"
|
| 317 |
except Exception as e:
|
| 318 |
return str(e)
|
| 319 |
|
|
|
|
| 453 |
text_input = gr.Textbox(label="input text",lines=5)
|
| 454 |
text_output = gr.Markdown(label="output text")
|
| 455 |
text_button = gr.Button("process text")
|
| 456 |
+
text_button.click(process_and_query, inputs=[input_language,audio_input,image_input,text_input], outputs=[gr.outputs.Textbox(label="Output"), gr.outputs.Label()]
|
| 457 |
gr.Examples([
|
| 458 |
["What is the proper treatment for buccal herpes?"],
|
| 459 |
["Male, 40 presenting with swollen glands and a rash"],
|