Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import openai
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Load .env file
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
openai.api_type = "azure"
|
| 12 |
+
openai.api_base = os.getenv("AZURE_API_ENDPOINT")
|
| 13 |
+
openai.api_version = "2024-02-01"
|
| 14 |
+
openai.api_key = os.getenv("AZURE_API_KEY")
|
| 15 |
+
print(f"Azure API token: {azure_api_key}")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def compare_claims(claim1, claim2):
|
| 19 |
+
try:
|
| 20 |
+
response = openai.ChatCompletion.create(
|
| 21 |
+
engine="gpt-4",
|
| 22 |
+
messages=[
|
| 23 |
+
{"role": "system", "content": "You are an AI specialized in claim comparison."},
|
| 24 |
+
{"role": "user", "content": f"Compare these two claims:\nClaim 1: {claim1}\nClaim 2: {claim2}\nWhat are the differences?"}
|
| 25 |
+
]
|
| 26 |
+
)
|
| 27 |
+
return response["choices"][0]["message"]["content"]
|
| 28 |
+
except Exception as e:
|
| 29 |
+
return {"error": str(e)}
|
| 30 |
+
|
| 31 |
+
def main():
|
| 32 |
+
"""
|
| 33 |
+
Launch the Gradio interface for sentiment analysis.
|
| 34 |
+
"""
|
| 35 |
+
# Define the Gradio interface
|
| 36 |
+
interface = gr.Interface(
|
| 37 |
+
fn=compare_claims,
|
| 38 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter Text Here..."),
|
| 39 |
+
outputs="json",
|
| 40 |
+
title="Text Classification with Azure Text Analytics",
|
| 41 |
+
description="This interface uses Azure Text Analytics to classify text sentiments. Enter a sentence to see its classification."
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
# Launch the Gradio app
|
| 45 |
+
interface.launch()
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
main()
|