File size: 1,868 Bytes
27fe163
822282c
 
 
 
27fe163
 
822282c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27fe163
822282c
27fe163
 
 
822282c
 
 
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
import gradio
import openai


# Getting responses using the OpenAI API
def response_chatgpt(api_key, country, city, season, days, hours):
    message = f"Sadece {days} gün sürecek {country} - {city} gezim olacak. Her gün toplamda gezmem için yalnızca {hours} saatim olacak. {season} en verimli turistik geziyi nasıl geçiririm.\n\nBunun için seyahat rehberi oluşturur musun?\n\nGeçireceğim gün sayısı kadar ve geçireceğim süre kadar plan oluşturur musun ve gideceğim yerler kolay ulaşabilir olsun. Giderken nasıl ulaşabileceğimi, bölgede bulabileceğim ulaşım araçlarını ve yiyebileceğim yemekleri ve o yemeklerin bulunduğu restoranlarını da ayrıca listeleyebilir misin?\n\nBana tamamen konuşma dilinde gibi cevap ver.  Hiç bir şekilde başlangıçta bir yazı yazmasın. Doğrudan günleri anlatsın. Başlangıç kısmı kesinlikle olmasın. Sanki bir insan yanıt veriyormuş gibi olsun. Tabii, Tabii ki, İşte, Hemen, elbette gibi yanıtlarla başlamasın."
    # OPENAI API KEY
    openai.api_key = api_key
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=message,
        max_tokens=1024,
        stream=True,
    )
    # Choosing best conversation
    completion_text = ''
    # iterate through the stream of events
    for event in response:
        event_text = event['choices'][0]['text']  # extract the text
        completion_text += event_text  # append the text

    return completion_text


# User input and web interface
chatbot = gradio.Interface(
    fn=response_chatgpt,
    inputs=["text", "text", "text", gradio.Dropdown(["ilkbahar", "yaz", "sonbahar", "kış"]),
            gradio.Dropdown(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]),
            gradio.Dropdown(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"])],
    outputs="text",
)
chatbot.launch()