Spaces:
Runtime error
Runtime error
valentin urena commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,21 +2,21 @@ import os
|
|
| 2 |
os.environ["KERAS_BACKEND"] = "torch" # "jax", "torch" or "tensorflow"
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
from typing import Iterator
|
| 11 |
import time
|
| 12 |
|
| 13 |
from chess_board import Game
|
| 14 |
from datasets import load_dataset
|
| 15 |
-
|
| 16 |
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
|
| 22 |
DESCRIPTION = """
|
|
@@ -38,13 +38,18 @@ Enjoy your game!
|
|
| 38 |
**- Valentin**
|
| 39 |
"""
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# Chat
|
| 47 |
-
# chat = model.start_chat()
|
| 48 |
|
| 49 |
# @spaces.GPU
|
| 50 |
def generate(
|
|
@@ -53,7 +58,7 @@ def generate(
|
|
| 53 |
max_new_tokens: int = 1024,
|
| 54 |
) -> Iterator[str]:
|
| 55 |
|
| 56 |
-
response =
|
| 57 |
|
| 58 |
outputs = ""
|
| 59 |
|
|
@@ -62,11 +67,6 @@ def generate(
|
|
| 62 |
yield outputs
|
| 63 |
|
| 64 |
|
| 65 |
-
# Load the dataset and convert to pandas DataFrame
|
| 66 |
-
ds = load_dataset("Lichess/chess-openings", split="train")
|
| 67 |
-
df = ds.to_pandas()
|
| 68 |
-
|
| 69 |
-
# Function to retrieve moves and name for a selected opening
|
| 70 |
def get_opening_details(opening_name):
|
| 71 |
opening_data = df[df['name'] == opening_name].iloc[0]
|
| 72 |
moves = opening_data['pgn']
|
|
@@ -77,11 +77,7 @@ def get_move_list(opening_name):
|
|
| 77 |
moves = opening_data['pgn']
|
| 78 |
pgn_string = moves.split()
|
| 79 |
return [move for idx,move in enumerate(pgn_string[1:],1) if idx%3!=0]
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
# Create a list of unique opening names
|
| 83 |
-
opening_names = df['name'].unique().tolist()
|
| 84 |
-
|
| 85 |
|
| 86 |
chat_interface = gr.ChatInterface(
|
| 87 |
fn=generate,
|
|
@@ -96,14 +92,11 @@ chat_interface = gr.ChatInterface(
|
|
| 96 |
)
|
| 97 |
|
| 98 |
|
| 99 |
-
with gr.Blocks(
|
| 100 |
-
font-size: 2px !important;
|
| 101 |
-
}""", fill_height=True) as demo:
|
| 102 |
gr.Markdown(DESCRIPTION)
|
| 103 |
|
| 104 |
play_match = Game()
|
| 105 |
|
| 106 |
-
# chess_png = gr.Image(play_match.display_board())
|
| 107 |
with gr.Row():
|
| 108 |
with gr.Column():
|
| 109 |
board_image = gr.HTML(play_match.display_board())
|
|
|
|
| 2 |
os.environ["KERAS_BACKEND"] = "torch" # "jax", "torch" or "tensorflow"
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
+
import keras_nlp
|
| 6 |
+
import keras
|
| 7 |
+
import spaces
|
| 8 |
+
import torch
|
| 9 |
|
| 10 |
from typing import Iterator
|
| 11 |
import time
|
| 12 |
|
| 13 |
from chess_board import Game
|
| 14 |
from datasets import load_dataset
|
| 15 |
+
import google.generativeai as genai
|
| 16 |
|
| 17 |
|
| 18 |
+
print(f"Is CUDA available: {torch.cuda.is_available()}")
|
| 19 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
| 20 |
|
| 21 |
|
| 22 |
DESCRIPTION = """
|
|
|
|
| 38 |
**- Valentin**
|
| 39 |
"""
|
| 40 |
|
| 41 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 42 |
+
genai.configure(api_key = api_key)
|
| 43 |
|
| 44 |
+
model = genai.GenerativeModel(model_name='gemini-1.5-flash-latest')
|
| 45 |
+
|
| 46 |
+
chat = model.start_chat()
|
| 47 |
+
|
| 48 |
+
ds = load_dataset("Lichess/chess-openings", split="train")
|
| 49 |
+
df = ds.to_pandas()
|
| 50 |
+
|
| 51 |
+
opening_names = df['name'].unique().tolist()
|
| 52 |
|
|
|
|
|
|
|
| 53 |
|
| 54 |
# @spaces.GPU
|
| 55 |
def generate(
|
|
|
|
| 58 |
max_new_tokens: int = 1024,
|
| 59 |
) -> Iterator[str]:
|
| 60 |
|
| 61 |
+
response = chat.send_message(message)
|
| 62 |
|
| 63 |
outputs = ""
|
| 64 |
|
|
|
|
| 67 |
yield outputs
|
| 68 |
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def get_opening_details(opening_name):
|
| 71 |
opening_data = df[df['name'] == opening_name].iloc[0]
|
| 72 |
moves = opening_data['pgn']
|
|
|
|
| 77 |
moves = opening_data['pgn']
|
| 78 |
pgn_string = moves.split()
|
| 79 |
return [move for idx,move in enumerate(pgn_string[1:],1) if idx%3!=0]
|
| 80 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
chat_interface = gr.ChatInterface(
|
| 83 |
fn=generate,
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
|
| 95 |
+
with gr.Blocks(css_path="styles.css", fill_height=True) as demo:
|
|
|
|
|
|
|
| 96 |
gr.Markdown(DESCRIPTION)
|
| 97 |
|
| 98 |
play_match = Game()
|
| 99 |
|
|
|
|
| 100 |
with gr.Row():
|
| 101 |
with gr.Column():
|
| 102 |
board_image = gr.HTML(play_match.display_board())
|