File size: 1,400 Bytes
fbe395f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7f4820
fbe395f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
import os
import requests
import gradio as gr

api_key = os.environ.get('MY_API_KEY')

def get_significant_events(year):
    # Define the API endpoint
    api_url = "https://api.nvcf.nvidia.com/v2/nvcf/pexec/functions/347fa3f3-d675-432c-b844-669ef8ee53df"
    headers = {
        'Authorization': f'Bearer {api_key}',
        'Content-Type': 'application/json'
    }
    
    # Construct the instruction in Chinese
    instruction = f"列出{year}年发生的主要事件"

    data = {
        "messages": [
            {"content": instruction, "role": "user"}
        ],
        "stream": False
    }

    # Make the API request
    response = requests.post(api_url, headers=headers, json=data)

    # Check the response status
    if response.status_code == 200:
        response_data = response.json()
        if 'choices' in response_data and len(response_data['choices']) > 0:
            content = response_data['choices'][0].get('message', {}).get('content', '')
            return content
        else:
            return "未找到相关信息"
    else:
        return f"错误: {response.text}"

# Create the Gradio interface with Chinese labels
interface = gr.Interface(
    fn=get_significant_events,
    inputs=gr.Textbox(label="年份", placeholder="输入年份..."),
    outputs=gr.Textbox(label="重大事件")
)

# Launch the app
if __name__ == "__main__":
    interface.launch()