Deila Proalfa
Update app.py
e208e45
raw
history blame
3.35 kB
from __future__ import annotations
from typing import Iterable
import gradio as Gradio
from gradio.themes.base import Base
from gradio.themes.utils import colors, fonts, sizes
from gpt4all import GPT4All
model = GPT4All("ggml-model-gpt4all-falcon-q4_0.bin")
theme = Gradio.themes.Monochrome(
primary_hue="cyan",
secondary_hue="cyan",
neutral_hue="neutral",
radius_size=Gradio.themes.sizes.radius_sm,
font=[Gradio.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
)
class CyanTheme(Base):
def __init__(
self,
*,
primary_hue: colors.Color | str = colors.cyan,
secondary_hue: colors.Color | str = colors.cyan,
neutral_hue: colors.Color | str = colors.neutral,
spacing_size: sizes.Size | str = sizes.spacing_md,
radius_size: sizes.Size | str = sizes.radius_md,
font: fonts.Font
| str
| Iterable[fonts.Font | str] = (
fonts.GoogleFont("Inter"),
"ui-sans-serif",
"sans-serif",
),
font_mono: fonts.Font
| str
| Iterable[fonts.Font | str] = (
fonts.GoogleFont("Space Grotesk"),
"ui-monospace",
"monospace",
),
):
super().__init__(
primary_hue=primary_hue,
secondary_hue=secondary_hue,
neutral_hue=neutral_hue,
spacing_size=spacing_size,
radius_size=radius_size,
font=font,
font_mono=font_mono,
)
super().set(
button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
button_primary_text_color="white",
button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
block_shadow="*shadow_drop_lg",
button_shadow="*shadow_drop_lg",
input_background_fill="zinc",
input_border_color="*secondary_300",
input_shadow="*shadow_drop",
input_shadow_focus="*shadow_drop_lg",
)
custom_theme = CyanTheme()
ins = '''### Instruction:
{}
### Response:
'''
def run_falcon(input, scrape, scrape_type):
result = ""
for token in model.generate(ins.format(input), max_tokens=768, streaming=True, repeat_penalty=1.3, repeat_last_n=64):
print(token)
result += token
yield result
with Gradio.Blocks(theme=custom_theme, analytics_enabled=False, css=".generating {visibility: hidden}") as demo:
with Gradio.Column():
Gradio.Markdown(
"""
## FREEGPT4ALL
Falcon Modell
Gib deine Frage in das untenstehende Feld ein und klicke auf den Button, um Antworten auf deine dringendsten Fragen zu erhalten!
"""
)
with Gradio.Row():
with Gradio.Box():
instruction = Gradio.components.Textbox(placeholder="Was stellt die philippinische Flagge dar?", label="Eingabe", info="Was möchtest du GPT4ALL fragen?")
scraping = Gradio.Checkbox(value=False, label="Web-Scraping für unbekannte Informationen durchführen", info="Scraping (Deaktiviert)")
scrape_type = Gradio.Radio(["Web-Scraping", "Kurzbeschreibungen"], label="Scraping-Taktik", info="Möchtest du, dass GPT4ALL Web-Scraping nutzt? Wenn ja—wie gründlich?")
with Gradio.Box():
output = Gradio.components.Textbox(value="", label="Ausgabe", info="Die Gedanken von GPT4ALL")
submit = Gradio.Button("Generieren", variant="primary")
submit.click(run_falcon, inputs=[instruction, scraping, scrape_type], outputs=[output])
demo.queue(concurrency_count=1).launch(debug=True) # type: ignore