Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- fka/awesome-chatgpt-prompts
|
5 |
+
- HuggingFaceFW/fineweb-2
|
6 |
+
language:
|
7 |
+
- ae
|
8 |
+
metrics:
|
9 |
+
- bleu
|
10 |
+
base_model:
|
11 |
+
- meta-llama/Llama-3.3-70B-Instruct
|
12 |
+
new_version: meta-llama/Llama-3.3-70B-Instruct
|
13 |
+
library_name: asteroid
|
14 |
+
---
|
15 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
16 |
+
import gradio as gr
|
17 |
+
|
18 |
+
# Načteme model GPT-J 6B a tokenizer
|
19 |
+
model_name = "EleutherAI/gpt-j-6B"
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
21 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
22 |
+
|
23 |
+
# Funkce pro generování odpovědí
|
24 |
+
def travel_assistant(input_text):
|
25 |
+
# Přizpůsobený prompt pro cestování
|
26 |
+
prompt = f"Jsi cestovatelský asistent. Pomáháš lidem s informacemi o cestování, včetně doporučení destinací, vízových informací, tipů na plány cest a místních tradic. Odpověz na následující dotaz: {input_text}"
|
27 |
+
|
28 |
+
# Tokenizace vstupu
|
29 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
30 |
+
|
31 |
+
# Generování odpovědi
|
32 |
+
outputs = model.generate(**inputs, max_length=200)
|
33 |
+
|
34 |
+
# Dekódování odpovědi
|
35 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
36 |
+
|
37 |
+
return generated_text
|
38 |
+
|
39 |
+
# Vytvoření uživatelského rozhraní s Gradio
|
40 |
+
iface = gr.Interface(fn=travel_assistant,
|
41 |
+
inputs="text",
|
42 |
+
outputs="text",
|
43 |
+
title="Cestovatelský asistent",
|
44 |
+
description="Ptejte se na tipy, doporučení destinací, víza a další cestovatelské informace. Například: 'Jaké jsou vízové požadavky pro Thajsko?'")
|
45 |
+
|
46 |
+
# Spuštění aplikace
|
47 |
+
iface.launch()
|
48 |
+
import requests
|
49 |
+
import pandas as pd
|
50 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
51 |
+
import gradio as gr
|
52 |
+
|
53 |
+
# Načteme model GPT-J 6B a tokenizer
|
54 |
+
model_name = "EleutherAI/gpt-j-6B"
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
56 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
57 |
+
|
58 |
+
# API klíče pro OpenWeather a CurrencyLayer
|
59 |
+
weather_api_key = "tvůj_openweather_api_klíč" # Získáš na https://openweathermap.org/api
|
60 |
+
currency_api_key = "tvůj_currencylayer_api_klíč" # Získáš na https://currencylayer.com/
|
61 |
+
|
62 |
+
# Funkce pro získání počasí
|
63 |
+
def get_weather(city):
|
64 |
+
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={weather_api_key}&units=metric&lang=cs"
|
65 |
+
response = requests.get(url)
|
66 |
+
data = response.json()
|
67 |
+
|
68 |
+
if data["cod"] != "404":
|
69 |
+
main_data = data["main"]
|
70 |
+
weather_data = data["weather"][0]
|
71 |
+
temperature = main_data["temp"]
|
72 |
+
description = weather_data["description"]
|
73 |
+
|
74 |
+
return f"Aktuální teplota v {city} je {temperature}°C, počasí: {description}."
|
75 |
+
else:
|
76 |
+
return "Město nenalezeno."
|
77 |
+
|
78 |
+
# Funkce pro získání směnných kurzů
|
79 |
+
def get_exchange_rate(from_currency, to_currency):
|
80 |
+
url = f"http://api.currencylayer.com/live?access_key={currency_api_key}¤cies={from_currency},{to_currency}&source={from_currency}&format=1"
|
81 |
+
response = requests.get(url)
|
82 |
+
data = response.json()
|
83 |
+
|
84 |
+
if data["success"]:
|
85 |
+
exchange_rate = data["quotes"][f"{from_currency}{to_currency}"]
|
86 |
+
return f"1 {from_currency} = {exchange_rate} {to_currency}"
|
87 |
+
else:
|
88 |
+
return "Nelze získat směnný kurz."
|
89 |
+
|
90 |
+
# Funkce pro generování tabulky s doporučenými destinacemi
|
91 |
+
def generate_travel_table():
|
92 |
+
data = {
|
93 |
+
"Destinace": ["Paříž", "Barcelona", "Řím", "New York", "Tokyo"],
|
94 |
+
"Typ dovolené": ["Romantická", "Plážová", "Historická", "Městská", "Kultura"],
|
95 |
+
"Průměrná cena (EUR)": [300, 250, 270, 400, 350],
|
96 |
+
"Vízové požadavky": ["Schengen", "Schengen", "Schengen", "ESTA", "Visa"]
|
97 |
+
}
|
98 |
+
|
99 |
+
df = pd.DataFrame(data)
|
100 |
+
return df
|
101 |
+
|
102 |
+
# Funkce pro generování odpovědí z modelu GPT-J
|
103 |
+
def travel_assistant(input_text):
|
104 |
+
if "počasí" in input_text.lower():
|
105 |
+
city = input_text.split("počasí v")[-1].strip()
|
106 |
+
return get_weather(city)
|
107 |
+
elif "směnný kurz" in input_text.lower():
|
108 |
+
currencies = input_text.split("směnný kurz mezi")[-1].strip().split(" a ")
|
109 |
+
if len(currencies) == 2:
|
110 |
+
return get_exchange_rate(currencies[0], currencies[1])
|
111 |
+
else:
|
112 |
+
return "Zadejte měny ve formátu: 'směnný kurz mezi CZK a USD'."
|
113 |
+
elif "tabulka" in input_text.lower():
|
114 |
+
return generate_travel_table()
|
115 |
+
else:
|
116 |
+
# Generování odpovědí na otázky o cestování
|
117 |
+
prompt = f"Jsi cestovatelský asistent. Pomáháš lidem s informacemi o cestování, včetně doporučení destinací, vízových informací, tipů na plány cest a místních tradic. Odpověz na následující dotaz: {input_text}"
|
118 |
+
|
119 |
+
# Tokenizace vstupu
|
120 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
121 |
+
|
122 |
+
# Generování odpovědi
|
123 |
+
outputs = model.generate(**inputs, max_length=200)
|
124 |
+
|
125 |
+
# Dekódování odpovědi
|
126 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
127 |
+
|
128 |
+
return generated_text
|
129 |
+
|
130 |
+
# Vytvoření uživatelského rozhraní s Gradio
|
131 |
+
iface = gr.Interface(fn=travel_assistant,
|
132 |
+
inputs="text",
|
133 |
+
outputs="text", # Text pro odpovědi nebo tabulky
|
134 |
+
title="Cestovatelský asistent",
|
135 |
+
description="Zadejte dotaz ohledně cestování, počasí, směnných kurzů nebo napište 'tabulka' pro seznam doporučených destinací.")
|
136 |
+
|
137 |
+
# Spuštění aplikace
|
138 |
+
iface.launch()
|