Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
|
4 |
+
# Load the model and tokenizer
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3.1-8B")
|
6 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3.1-8B")
|
7 |
+
|
8 |
+
def generate_text(prompt, max_length=150):
|
9 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
10 |
+
outputs = model.generate(**inputs, max_length=max_length, num_return_sequences=1, do_sample=True)
|
11 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
12 |
+
|
13 |
+
def generate_argument(topic, stance):
|
14 |
+
prompt = f"Generate a compelling argument for the following debate topic.\nTopic: {topic}\nStance: {stance}\nArgument:"
|
15 |
+
response = generate_text(prompt, max_length=200)
|
16 |
+
argument = response.split("Argument:")[1].strip()
|
17 |
+
return argument
|
18 |
+
|
19 |
+
def generate_counterargument(topic, original_argument):
|
20 |
+
prompt = f"Generate a strong counterargument for the following debate topic and argument.\nTopic: {topic}\nOriginal Argument: {original_argument}\nCounterargument:"
|
21 |
+
response = generate_text(prompt, max_length=200)
|
22 |
+
counterargument = response.split("Counterargument:")[1].strip()
|
23 |
+
return counterargument
|
24 |
+
|
25 |
+
def debate_assistant(topic, stance):
|
26 |
+
argument = generate_argument(topic, stance)
|
27 |
+
counterargument = generate_counterargument(topic, argument)
|
28 |
+
return f"Argument: {argument}\n\nCounterargument: {counterargument}"
|
29 |
+
|
30 |
+
# Create the Gradio interface
|
31 |
+
iface = gr.Interface(
|
32 |
+
fn=debate_assistant,
|
33 |
+
inputs=[
|
34 |
+
gr.Textbox(label="Debate Topic"),
|
35 |
+
gr.Radio(["For", "Against"], label="Stance")
|
36 |
+
],
|
37 |
+
outputs=gr.Textbox(label="Generated Debate Arguments"),
|
38 |
+
title="AI-powered Debate Assistant (Meta-Llama 3.1)",
|
39 |
+
description="Enter a debate topic and choose a stance to generate arguments and counterarguments using Meta-Llama 3.1."
|
40 |
+
)
|
41 |
+
|
42 |
+
# Launch the interface
|
43 |
+
iface.launch()
|