Spaces:
Sleeping
Sleeping
Commit
·
444b436
1
Parent(s):
5bc3145
Add application file, requirements file and .env file
Browse files- .gitignore +2 -0
- app.py +40 -0
- requirements.txt +3 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
.env
|
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
def generate_upf_code(message, history):
|
| 9 |
+
api_url = "https://api.dify.ai/v1/chat-messages"
|
| 10 |
+
api_key = os.getenv("API_KEY")
|
| 11 |
+
|
| 12 |
+
headers = {
|
| 13 |
+
"Authorization": f"Bearer {api_key}",
|
| 14 |
+
"Content-Type": "application/json"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
payload = {
|
| 18 |
+
"inputs": {},
|
| 19 |
+
"query": message,
|
| 20 |
+
"response_mode": "blocking",
|
| 21 |
+
"conversation_id": "",
|
| 22 |
+
"user": "abc-123"
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
| 26 |
+
|
| 27 |
+
if not response.ok:
|
| 28 |
+
raise Exception(f"API Error: {response.status_code} {response.reason}")
|
| 29 |
+
|
| 30 |
+
data = response.json()
|
| 31 |
+
answer = data["answer"]
|
| 32 |
+
return answer
|
| 33 |
+
|
| 34 |
+
gr.ChatInterface(
|
| 35 |
+
fn=generate_upf_code,
|
| 36 |
+
type="messages",
|
| 37 |
+
title="UPF Code Generator",
|
| 38 |
+
description="Ask me to generate UPF code for your design constraints.",
|
| 39 |
+
theme="ocean"
|
| 40 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests
|
| 2 |
+
gradio
|
| 3 |
+
python-dotenv
|