Spaces:
Build error
Build error
nakyung1007 commited on
Commit ·
b557476
1
Parent(s): 4e3dd44
gradio 간단한 파이썬 추가3
Browse files
app.py
CHANGED
|
@@ -1,9 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
demo.launch()
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
|
| 3 |
+
# # 간단한 인사 함수
|
| 4 |
+
# def greet(name):
|
| 5 |
+
# return f"Hello {name}!"
|
| 6 |
+
|
| 7 |
+
# # Gradio 인터페이스 정의
|
| 8 |
+
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 9 |
+
# demo.launch()
|
| 10 |
import gradio as gr
|
| 11 |
+
import requests
|
| 12 |
+
|
| 13 |
+
# Azure OpenAI API 호출 함수
|
| 14 |
+
def ask_gpt(user_text):
|
| 15 |
+
endpoint = "https://5b040-openai.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-02-15-preview"
|
| 16 |
+
api_key = "6tuIuMEHIu3wJHSnkBCXFqaNnKcmraKNgm6mS585Q6auFzJBvLfAJQQJ99AKACfhMk5XJ3w3AAABACOGO5fD"
|
| 17 |
+
|
| 18 |
+
headers = {
|
| 19 |
+
"Content-Type": "application/json",
|
| 20 |
+
"api-key": api_key
|
| 21 |
+
}
|
| 22 |
+
payload = {
|
| 23 |
+
"messages": [
|
| 24 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
| 25 |
+
{"role": "user", "content": user_text}
|
| 26 |
+
],
|
| 27 |
+
"temperature": 0.7,
|
| 28 |
+
"max_tokens": 800
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
response = requests.post(endpoint, headers=headers, json=payload)
|
| 32 |
+
if response.status_code == 200:
|
| 33 |
+
return response.json()["choices"][0]["message"]["content"]
|
| 34 |
+
else:
|
| 35 |
+
return f"Error: {response.status_code}, {response.text}"
|
| 36 |
|
| 37 |
+
# Gradio 인터페이스
|
| 38 |
+
interface = gr.Interface(
|
| 39 |
+
fn=ask_gpt,
|
| 40 |
+
inputs="text",
|
| 41 |
+
outputs="text",
|
| 42 |
+
title="Azure OpenAI Chat",
|
| 43 |
+
description="Azure OpenAI API를 통해 GPT 모델과 상호작용할 수 있는 인터페이스입니다."
|
| 44 |
+
)
|
| 45 |
|
| 46 |
+
# 실행
|
| 47 |
+
interface.launch()
|
|
|