File size: 1,410 Bytes
b557476
 
 
 
 
 
 
 
 
24fb969
b557476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24fb969
b557476
 
 
 
 
 
 
 
24fb969
b557476
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# import gradio as gr

# # ๊ฐ„๋‹จํ•œ ์ธ์‚ฌ ํ•จ์ˆ˜
# def greet(name):
#     return f"Hello {name}!"

# # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# demo.launch()
import gradio as gr
import requests

# Azure OpenAI API ํ˜ธ์ถœ ํ•จ์ˆ˜
def ask_gpt(user_text):
    endpoint = "https://5b040-openai.openai.azure.com/openai/deployments/gpt-4o-mini/chat/completions?api-version=2024-02-15-preview"
    api_key = "6tuIuMEHIu3wJHSnkBCXFqaNnKcmraKNgm6mS585Q6auFzJBvLfAJQQJ99AKACfhMk5XJ3w3AAABACOGO5fD"
    
    headers = {
        "Content-Type": "application/json",
        "api-key": api_key
    }
    payload = {
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": user_text}
        ],
        "temperature": 0.7,
        "max_tokens": 800
    }
    
    response = requests.post(endpoint, headers=headers, json=payload)
    if response.status_code == 200:
        return response.json()["choices"][0]["message"]["content"]
    else:
        return f"Error: {response.status_code}, {response.text}"

# Gradio ์ธํ„ฐํŽ˜์ด์Šค
interface = gr.Interface(
    fn=ask_gpt,
    inputs="text",
    outputs="text",
    title="Azure OpenAI Chat",
    description="Azure OpenAI API๋ฅผ ํ†ตํ•ด GPT ๋ชจ๋ธ๊ณผ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ธํ„ฐํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค."
)

# ์‹คํ–‰
interface.launch()