akhaliq HF staff commited on
Commit
82939de
·
verified ·
1 Parent(s): e801e50

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +27 -37
index.html CHANGED
@@ -1,49 +1,39 @@
1
- <!DOCTYPE html>
2
  <html>
3
  <head>
4
- <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite@0.4.1/dist/lite.js"></script>
5
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite@0.4.1/dist/lite.css" />
6
  </head>
7
  <body>
8
- <gradio-lite>
 
 
 
 
9
 
10
- <gradio-requirements>
11
- transformers_js_py
12
- </gradio-requirements>
13
 
14
-
15
- import gradio as gr
16
- import random
17
 
18
- FORTUNES = [
19
- "A pleasant surprise is waiting for you.",
20
- "Your hard work will pay off in the near future.",
21
- "A new opportunity will present itself soon.",
22
- "Your creativity will lead you to success.",
23
- "An unexpected journey will bring you joy.",
24
- "A wise decision lies ahead of you.",
25
- "Your kindness will be rewarded tenfold.",
26
- "A long-lost friend will reenter your life.",
27
- "Your persistence will overcome current challenges.",
28
- "A positive change is on the horizon."
29
- ]
30
 
31
- def get_fortune(name):
32
- if not name.strip():
33
- return "Please enter your name to receive a fortune."
34
- fortune = random.choice(FORTUNES)
35
- return f"{name.strip()}, your fortune: {fortune}"
36
 
37
- with gr.Blocks() as demo:
38
- gr.Markdown("# 🥠 Fortune Cookie Generator")
39
- name_input = gr.Textbox(label="Your Name")
40
- fortune_output = gr.Textbox(label="Your Fortune")
41
- submit_button = gr.Button("Get Fortune")
42
-
43
- submit_button.click(fn=get_fortune, inputs=name_input, outputs=fortune_output)
44
 
45
- if __name__ == "__main__":
46
- demo.launch()
47
- </gradio-lite>
 
 
48
  </body>
49
  </html>
 
 
1
  <html>
2
  <head>
3
+ <script type="module" crossorigin src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
4
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
5
  </head>
6
  <body>
7
+ <gradio-lite>
8
+ <gradio-requirements>transformers_js_py</gradio-requirements>
9
+ <gradio-file name="app.py" entrypoint>
10
+ from transformers_js import pipeline
11
+ import gradio as gr
12
 
13
+ fortune_generator = await pipeline('text-generation', 'Xenova/distilgpt2')
 
 
14
 
15
+ async def generate_fortune(name):
16
+ if not name.strip():
17
+ return "Please enter your name to receive a fortune."
18
 
19
+ prompt = f"Fortune for {name}: In the near future, you will"
20
+ result = await fortune_generator(prompt, max_new_tokens=30, temperature=0.7)
21
+ fortune = result[0]['generated_text'].replace(prompt, '')
 
 
 
 
 
 
 
 
 
22
 
23
+ return f"{name.strip()}, your fortune: In the near future, you will{fortune}"
24
+
25
+ with gr.Blocks(title="AI Fortune Cookie Generator") as demo:
26
+ gr.Markdown("# 🥠 AI Fortune Cookie Generator")
27
+ gr.Markdown("Enter your name and receive a personalized AI-generated fortune!")
28
 
29
+ name_input = gr.Textbox(label="Your Name")
30
+ fortune_output = gr.Textbox(label="Your AI-Generated Fortune")
31
+ submit_button = gr.Button("🔮 Reveal Your Fortune")
 
 
 
 
32
 
33
+ submit_button.click(fn=generate_fortune, inputs=name_input, outputs=fortune_output)
34
+
35
+ demo.launch()
36
+ </gradio-file>
37
+ </gradio-lite>
38
  </body>
39
  </html>