musaashaikh's picture
Update app.py
1c19215 verified
import gradio as gr
import os
import openai
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Azure OpenAI Configuration
openai.api_type = "azure"
openai.api_base = os.getenv("AZURE_API_ENDPOINT")
openai.api_key = os.getenv("AZURE_API_KEY")
def compare_claims(claim1, claim2):
"""
Function to compare two claims using Azure OpenAI's GPT model.
"""
response = openai.ChatCompletion.create(
engine="gpt-4",
messages=[
{"role": "system", "content": "You are an AI specialized in claim comparison."},
{"role": "user", "content": f"Compare these two claims:\nClaim 1: {claim1}\nClaim 2: {claim2}\nWhat are the differences?"}
]
)
return response["choices"][0]["message"]["content"]
def main():
"""
Launch the Gradio interface for claim comparison.
"""
# Define the Gradio interface
interface = gr.Interface(
fn=compare_claims,
inputs=[
gr.Textbox(label="claim1", placeholder="Enter first claim description..."),
gr.Textbox(label="claim2", placeholder="Enter second claim description...")
],
outputs="text",
title="Claims Comparison",
description="Enter two claims to compare their differences."
)
# Launch the Gradio app
interface.launch()
if __name__ == "__main__":
main()